diff options
44 files changed, 1722 insertions, 497 deletions
diff --git a/chrome/test/nacl_test_injection/buildbot_nacl_integration.py b/chrome/test/nacl_test_injection/buildbot_nacl_integration.py index 9fbd944..62a3781 100755 --- a/chrome/test/nacl_test_injection/buildbot_nacl_integration.py +++ b/chrome/test/nacl_test_injection/buildbot_nacl_integration.py @@ -49,6 +49,9 @@ def Main(args): tests_to_disable.append('run_pm_redir_stderr_bg_1000000_chrome_browser_test') # http://code.google.com/p/nativeclient/issues/detail?id=2511 tests_to_disable.append('run_ppapi_ppb_image_data_browser_test') + # Font API is only exported to trusted plugins now, and this test should be + # removed. + tests_to_disable.append('run_ppapi_example_font_test') # TODO(ncbray) why did these tests flake? # http://code.google.com/p/nativeclient/issues/detail?id=2230 diff --git a/chrome/test/ui/ppapi_uitest.cc b/chrome/test/ui/ppapi_uitest.cc index 3aa81b6..5e17212 100644 --- a/chrome/test/ui/ppapi_uitest.cc +++ b/chrome/test/ui/ppapi_uitest.cc @@ -378,6 +378,9 @@ TEST_PPAPI_IN_PROCESS(ImageData) TEST_PPAPI_OUT_OF_PROCESS(ImageData) TEST_PPAPI_NACL_VIA_HTTP(ImageData) +TEST_PPAPI_IN_PROCESS(BrowserFont) +TEST_PPAPI_OUT_OF_PROCESS(BrowserFont) + TEST_PPAPI_IN_PROCESS(Buffer) TEST_PPAPI_OUT_OF_PROCESS(Buffer) diff --git a/content/browser/renderer_host/pepper_message_filter.cc b/content/browser/renderer_host/pepper_message_filter.cc index 2a3b94d..4abbb5a 100644 --- a/content/browser/renderer_host/pepper_message_filter.cc +++ b/content/browser/renderer_host/pepper_message_filter.cc @@ -92,7 +92,7 @@ bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg, #endif // ENABLE_FLAPPER_HACKS IPC_MESSAGE_HANDLER(PepperMsg_GetLocalTimeZoneOffset, OnGetLocalTimeZoneOffset) - IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_PPBFont_GetFontFamilies, + IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_PPBInstance_GetFontFamilies, OnGetFontFamilies) // TCP messages. IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPSocket_Create, OnTCPCreate) @@ -564,7 +564,7 @@ void PepperMessageFilter::GetFontFamiliesComplete( output.push_back(0); } - PpapiHostMsg_PPBFont_GetFontFamilies::WriteReplyParams(reply_msg, output); + PpapiHostMsg_PPBInstance_GetFontFamilies::WriteReplyParams(reply_msg, output); Send(reply_msg); } diff --git a/ppapi/api/trusted/ppb_browser_font_trusted.idl b/ppapi/api/trusted/ppb_browser_font_trusted.idl new file mode 100644 index 0000000..7c0c633 --- /dev/null +++ b/ppapi/api/trusted/ppb_browser_font_trusted.idl @@ -0,0 +1,257 @@ +/* Copyright (c) 2012 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/** + * This file defines the <code>PPB_BrowserFont_Trusted</code> interface. + */ +label Chrome { + M19 = 1.0 +}; + +[assert_size(4)] +enum PP_BrowserFont_Trusted_Family { + /** + * Uses the user's default web page font (normally either the default serif + * or sans serif font). + */ + PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT = 0, + + /** + * These families will use the default web page font corresponding to the + * given family. + */ + PP_BROWSERFONT_TRUSTED_FAMILY_SERIF = 1, + PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF = 2, + PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE = 3 +}; + +/** + * Specifies the font weight. Normally users will only use NORMAL or BOLD. + */ +[assert_size(4)] +enum PP_BrowserFont_Trusted_Weight { + PP_BROWSERFONT_TRUSTED_WEIGHT_100 = 0, + PP_BROWSERFONT_TRUSTED_WEIGHT_200 = 1, + PP_BROWSERFONT_TRUSTED_WEIGHT_300 = 2, + PP_BROWSERFONT_TRUSTED_WEIGHT_400 = 3, + PP_BROWSERFONT_TRUSTED_WEIGHT_500 = 4, + PP_BROWSERFONT_TRUSTED_WEIGHT_600 = 5, + PP_BROWSERFONT_TRUSTED_WEIGHT_700 = 6, + PP_BROWSERFONT_TRUSTED_WEIGHT_800 = 7, + PP_BROWSERFONT_TRUSTED_WEIGHT_900 = 8, + PP_BROWSERFONT_TRUSTED_WEIGHT_NORMAL = + PP_BROWSERFONT_TRUSTED_WEIGHT_400, + PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD = + PP_BROWSERFONT_TRUSTED_WEIGHT_700 +}; + +[assert_size(48)] +struct PP_BrowserFont_Trusted_Description { + /** + * Font face name as a string. This can also be an undefined var, in which + * case the generic family will be obeyed. If the face is not available on + * the system, the browser will attempt to do font fallback or pick a default + * font. + */ + PP_Var face; + + /** + * When Create()ing a font and the face is an undefined var, the family + * specifies the generic font family type to use. If the face is specified, + * this will be ignored. + * + * When Describe()ing a font, the family will be the value you passed in when + * the font was created. In other words, if you specify a face name, the + * family will not be updated to reflect whether the font name you requested + * is serif or sans serif. + */ + PP_BrowserFont_Trusted_Family family; + + /** + * Size in pixels. + * + * You can specify 0 to get the default font size. The default font size + * may vary depending on the requested font. The typical example is that + * the user may have a different font size for the default monospace font to + * give it a similar optical size to the proportionally spaced fonts. + */ + uint32_t size; + + /** + * Normally you will use either normal or bold. + */ + PP_BrowserFont_Trusted_Weight weight; + + PP_Bool italic; + PP_Bool small_caps; + + /** + * Adjustment to apply to letter and word spacing, respectively. Initialize + * to 0 to get normal spacing. Negative values bring letters/words closer + * together, positive values separate them. + */ + int32_t letter_spacing; + int32_t word_spacing; + + /** + * Ensure that this struct is 48-bytes wide by padding the end. In some + * compilers, PP_Var is 8-byte aligned, so those compilers align this struct + * on 8-byte boundaries as well and pad it to 16 bytes even without this + * padding attribute. This padding makes its size consistent across + * compilers. + */ + int32_t padding; +}; + +[assert_size(20)] +struct PP_BrowserFont_Trusted_Metrics { + int32_t height; + int32_t ascent; + int32_t descent; + int32_t line_spacing; + int32_t x_height; +}; + +[assert_size(24)] +struct PP_BrowserFont_Trusted_TextRun { + /** + * This var must either be a string or a null/undefined var (which will be + * treated as a 0-length string). + */ + PP_Var text; + + /** + * Set to PP_TRUE if the text is right-to-left. + */ + PP_Bool rtl; + + /** + * Set to PP_TRUE to force the directionality of the text regardless of + * content + */ + PP_Bool override_direction; +}; + +/** + * Provides an interface for native browser text rendering. + * + * This API is "trusted" not for security reasons, but because it can not be + * implemented efficiently when running out-of-process in Browser Client. In + * this case, WebKit is in another process and every text call would require a + * synchronous IPC to the renderer. It is, however, available to native + * (non-NaCl) out-of-process PPAPI plugins since WebKit is available in the + * plugin process. + */ +interface PPB_BrowserFont_Trusted { + /** + * Returns a list of all available font families on the system. You can use + * this list to decide whether to Create() a font. + * + * The return value will be a single string with null characters delimiting + * the end of each font name. For example: "Arial\0Courier\0Times\0". + * + * Returns an undefined var on failure (this typically means you passed an + * invalid instance). + */ + PP_Var GetFontFamilies( + [in] PP_Instance instance); + + /** + * Returns a font which best matches the given description. The return value + * will have a non-zero ID on success, or zero on failure. + */ + PP_Resource Create( + [in] PP_Instance instance, + [in] PP_BrowserFont_Trusted_Description description); + + /** + * Returns PP_TRUE if the given resource is a Font. Returns PP_FALSE if the + * resource is invalid or some type other than a Font. + */ + PP_Bool IsFont( + [in] PP_Resource resource); + + /** + * Loads the description and metrics of the font into the given structures. + * The description will be different than the description the font was + * created with since it will be filled with the real values from the font + * that was actually selected. + * + * The PP_Var in the description should be of type Void on input. On output, + * this will contain the string and will have a reference count of 1. The + * plugin is responsible for calling Release on this var. + * + * Returns PP_TRUE on success, PP_FALSE if the font is invalid or if the Var + * in the description isn't Null (to prevent leaks). + */ + PP_Bool Describe( + [in] PP_Resource font, + [out] PP_BrowserFont_Trusted_Description description, + [out] PP_BrowserFont_Trusted_Metrics metrics); + + /** + * Draws the text to the image buffer. + * + * The given point represents the baseline of the left edge of the font, + * regardless of whether it is left-to-right or right-to-left (in the case of + * RTL text, this will actually represent the logical end of the text). + * + * The clip is optional and may be NULL. In this case, the text will be + * clipped to the image. + * + * The image_data_is_opaque flag indicates whether subpixel antialiasing can + * be performend, if it is supported. When the image below the text is + * opaque, subpixel antialiasing is supported and you should set this to + * PP_TRUE to pick up the user's default preferences. If your plugin is + * partially transparent, then subpixel antialiasing is not possible and + * grayscale antialiasing will be used instead (assuming the user has + * antialiasing enabled at all). + */ + PP_Bool DrawTextAt( + [in] PP_Resource font, + [in] PP_Resource image_data, + [in] PP_BrowserFont_Trusted_TextRun text, + [in] PP_Point position, + [in] uint32_t color, + [in] PP_Rect clip, + [in] PP_Bool image_data_is_opaque); + + /** + * Returns the width of the given string. If the font is invalid or the var + * isn't a valid string, this will return -1. + * + * Note that this function handles complex scripts such as Arabic, combining + * accents, etc. so that adding the width of substrings won't necessarily + * produce the correct width of the entire string. + * + * Returns -1 on failure. + */ + int32_t MeasureText( + [in] PP_Resource font, + [in] PP_BrowserFont_Trusted_TextRun text); + + /** + * Returns the character at the given pixel X position from the beginning of + * the string. This handles complex scripts such as Arabic, where characters + * may be combined or replaced depending on the context. Returns (uint32)-1 + * on failure. + */ + uint32_t CharacterOffsetForPixel( + [in] PP_Resource font, + [in] PP_BrowserFont_Trusted_TextRun text, + [in] int32_t pixel_position); + + /** + * Returns the horizontal advance to the given character if the string was + * placed at the given position. This handles complex scripts such as Arabic, + * where characters may be combined or replaced depending on context. Returns + * -1 on error. + */ + int32_t PixelOffsetForCharacter( + [in] PP_Resource font, + [in] PP_BrowserFont_Trusted_TextRun text, + [in] uint32_t char_offset); +}; + diff --git a/ppapi/c/trusted/ppb_browser_font_trusted.h b/ppapi/c/trusted/ppb_browser_font_trusted.h new file mode 100644 index 0000000..080d024 --- /dev/null +++ b/ppapi/c/trusted/ppb_browser_font_trusted.h @@ -0,0 +1,278 @@ +/* Copyright (c) 2012 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* From trusted/ppb_browser_font_trusted.idl, + * modified Tue Feb 14 08:45:20 2012. + */ + +#ifndef PPAPI_C_TRUSTED_PPB_BROWSER_FONT_TRUSTED_H_ +#define PPAPI_C_TRUSTED_PPB_BROWSER_FONT_TRUSTED_H_ + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_macros.h" +#include "ppapi/c/pp_point.h" +#include "ppapi/c/pp_rect.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/pp_size.h" +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/pp_var.h" + +#define PPB_BROWSERFONT_TRUSTED_INTERFACE_1_0 "PPB_BrowserFont_Trusted;1.0" +#define PPB_BROWSERFONT_TRUSTED_INTERFACE PPB_BROWSERFONT_TRUSTED_INTERFACE_1_0 + +/** + * @file + * This file defines the <code>PPB_BrowserFont_Trusted</code> interface. + */ + + +/** + * @addtogroup Enums + * @{ + */ +typedef enum { + /** + * Uses the user's default web page font (normally either the default serif + * or sans serif font). + */ + PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT = 0, + /** + * These families will use the default web page font corresponding to the + * given family. + */ + PP_BROWSERFONT_TRUSTED_FAMILY_SERIF = 1, + PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF = 2, + PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE = 3 +} PP_BrowserFont_Trusted_Family; +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_BrowserFont_Trusted_Family, 4); + +/** + * Specifies the font weight. Normally users will only use NORMAL or BOLD. + */ +typedef enum { + PP_BROWSERFONT_TRUSTED_WEIGHT_100 = 0, + PP_BROWSERFONT_TRUSTED_WEIGHT_200 = 1, + PP_BROWSERFONT_TRUSTED_WEIGHT_300 = 2, + PP_BROWSERFONT_TRUSTED_WEIGHT_400 = 3, + PP_BROWSERFONT_TRUSTED_WEIGHT_500 = 4, + PP_BROWSERFONT_TRUSTED_WEIGHT_600 = 5, + PP_BROWSERFONT_TRUSTED_WEIGHT_700 = 6, + PP_BROWSERFONT_TRUSTED_WEIGHT_800 = 7, + PP_BROWSERFONT_TRUSTED_WEIGHT_900 = 8, + PP_BROWSERFONT_TRUSTED_WEIGHT_NORMAL = PP_BROWSERFONT_TRUSTED_WEIGHT_400, + PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD = PP_BROWSERFONT_TRUSTED_WEIGHT_700 +} PP_BrowserFont_Trusted_Weight; +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_BrowserFont_Trusted_Weight, 4); +/** + * @} + */ + +/** + * @addtogroup Structs + * @{ + */ +struct PP_BrowserFont_Trusted_Description { + /** + * Font face name as a string. This can also be an undefined var, in which + * case the generic family will be obeyed. If the face is not available on + * the system, the browser will attempt to do font fallback or pick a default + * font. + */ + struct PP_Var face; + /** + * When Create()ing a font and the face is an undefined var, the family + * specifies the generic font family type to use. If the face is specified, + * this will be ignored. + * + * When Describe()ing a font, the family will be the value you passed in when + * the font was created. In other words, if you specify a face name, the + * family will not be updated to reflect whether the font name you requested + * is serif or sans serif. + */ + PP_BrowserFont_Trusted_Family family; + /** + * Size in pixels. + * + * You can specify 0 to get the default font size. The default font size + * may vary depending on the requested font. The typical example is that + * the user may have a different font size for the default monospace font to + * give it a similar optical size to the proportionally spaced fonts. + */ + uint32_t size; + /** + * Normally you will use either normal or bold. + */ + PP_BrowserFont_Trusted_Weight weight; + PP_Bool italic; + PP_Bool small_caps; + /** + * Adjustment to apply to letter and word spacing, respectively. Initialize + * to 0 to get normal spacing. Negative values bring letters/words closer + * together, positive values separate them. + */ + int32_t letter_spacing; + int32_t word_spacing; + /** + * Ensure that this struct is 48-bytes wide by padding the end. In some + * compilers, PP_Var is 8-byte aligned, so those compilers align this struct + * on 8-byte boundaries as well and pad it to 16 bytes even without this + * padding attribute. This padding makes its size consistent across + * compilers. + */ + int32_t padding; +}; +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_BrowserFont_Trusted_Description, 48); + +struct PP_BrowserFont_Trusted_Metrics { + int32_t height; + int32_t ascent; + int32_t descent; + int32_t line_spacing; + int32_t x_height; +}; +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_BrowserFont_Trusted_Metrics, 20); + +struct PP_BrowserFont_Trusted_TextRun { + /** + * This var must either be a string or a null/undefined var (which will be + * treated as a 0-length string). + */ + struct PP_Var text; + /** + * Set to PP_TRUE if the text is right-to-left. + */ + PP_Bool rtl; + /** + * Set to PP_TRUE to force the directionality of the text regardless of + * content + */ + PP_Bool override_direction; +}; +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_BrowserFont_Trusted_TextRun, 24); +/** + * @} + */ + +/** + * @addtogroup Interfaces + * @{ + */ +/** + * Provides an interface for native browser text rendering. + * + * This API is "trusted" not for security reasons, but because it can not be + * implemented efficiently when running out-of-process in Browser Client. In + * this case, WebKit is in another process and every text call would require a + * synchronous IPC to the renderer. It is, however, available to native + * (non-NaCl) out-of-process PPAPI plugins since WebKit is available in the + * plugin process. + */ +struct PPB_BrowserFont_Trusted_1_0 { + /** + * Returns a list of all available font families on the system. You can use + * this list to decide whether to Create() a font. + * + * The return value will be a single string with null characters delimiting + * the end of each font name. For example: "Arial\0Courier\0Times\0". + * + * Returns an undefined var on failure (this typically means you passed an + * invalid instance). + */ + struct PP_Var (*GetFontFamilies)(PP_Instance instance); + /** + * Returns a font which best matches the given description. The return value + * will have a non-zero ID on success, or zero on failure. + */ + PP_Resource (*Create)( + PP_Instance instance, + const struct PP_BrowserFont_Trusted_Description* description); + /** + * Returns PP_TRUE if the given resource is a Font. Returns PP_FALSE if the + * resource is invalid or some type other than a Font. + */ + PP_Bool (*IsFont)(PP_Resource resource); + /** + * Loads the description and metrics of the font into the given structures. + * The description will be different than the description the font was + * created with since it will be filled with the real values from the font + * that was actually selected. + * + * The PP_Var in the description should be of type Void on input. On output, + * this will contain the string and will have a reference count of 1. The + * plugin is responsible for calling Release on this var. + * + * Returns PP_TRUE on success, PP_FALSE if the font is invalid or if the Var + * in the description isn't Null (to prevent leaks). + */ + PP_Bool (*Describe)(PP_Resource font, + struct PP_BrowserFont_Trusted_Description* description, + struct PP_BrowserFont_Trusted_Metrics* metrics); + /** + * Draws the text to the image buffer. + * + * The given point represents the baseline of the left edge of the font, + * regardless of whether it is left-to-right or right-to-left (in the case of + * RTL text, this will actually represent the logical end of the text). + * + * The clip is optional and may be NULL. In this case, the text will be + * clipped to the image. + * + * The image_data_is_opaque flag indicates whether subpixel antialiasing can + * be performend, if it is supported. When the image below the text is + * opaque, subpixel antialiasing is supported and you should set this to + * PP_TRUE to pick up the user's default preferences. If your plugin is + * partially transparent, then subpixel antialiasing is not possible and + * grayscale antialiasing will be used instead (assuming the user has + * antialiasing enabled at all). + */ + PP_Bool (*DrawTextAt)(PP_Resource font, + PP_Resource image_data, + const struct PP_BrowserFont_Trusted_TextRun* text, + const struct PP_Point* position, + uint32_t color, + const struct PP_Rect* clip, + PP_Bool image_data_is_opaque); + /** + * Returns the width of the given string. If the font is invalid or the var + * isn't a valid string, this will return -1. + * + * Note that this function handles complex scripts such as Arabic, combining + * accents, etc. so that adding the width of substrings won't necessarily + * produce the correct width of the entire string. + * + * Returns -1 on failure. + */ + int32_t (*MeasureText)(PP_Resource font, + const struct PP_BrowserFont_Trusted_TextRun* text); + /** + * Returns the character at the given pixel X position from the beginning of + * the string. This handles complex scripts such as Arabic, where characters + * may be combined or replaced depending on the context. Returns (uint32)-1 + * on failure. + */ + uint32_t (*CharacterOffsetForPixel)( + PP_Resource font, + const struct PP_BrowserFont_Trusted_TextRun* text, + int32_t pixel_position); + /** + * Returns the horizontal advance to the given character if the string was + * placed at the given position. This handles complex scripts such as Arabic, + * where characters may be combined or replaced depending on context. Returns + * -1 on error. + */ + int32_t (*PixelOffsetForCharacter)( + PP_Resource font, + const struct PP_BrowserFont_Trusted_TextRun* text, + uint32_t char_offset); +}; + +typedef struct PPB_BrowserFont_Trusted_1_0 PPB_BrowserFont_Trusted; +/** + * @} + */ + +#endif /* PPAPI_C_TRUSTED_PPB_BROWSER_FONT_TRUSTED_H_ */ + diff --git a/ppapi/cpp/trusted/browser_font_trusted.cc b/ppapi/cpp/trusted/browser_font_trusted.cc new file mode 100644 index 0000000..8bea86a --- /dev/null +++ b/ppapi/cpp/trusted/browser_font_trusted.cc @@ -0,0 +1,276 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/trusted/browser_font_trusted.h" + +#include <algorithm> + +#include "ppapi/c/dev/ppb_font_dev.h" +#include "ppapi/cpp/image_data.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/point.h" +#include "ppapi/cpp/rect.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_BrowserFont_Trusted>() { + return PPB_BROWSERFONT_TRUSTED_INTERFACE; +} +template <> const char* interface_name<PPB_Font_Dev>() { + return PPB_FONT_DEV_INTERFACE; +} + +// This class provides backwards compat for PPB_Font, which is binary +// compatible with the BrowserFont interface. +// TODO(brettw) remove PPB_Font altogether when Flash is updated. +const PP_FontDescription_Dev* BrowserFontDescToFontDesc( + const PP_BrowserFont_Trusted_Description* desc) { + return reinterpret_cast<const PP_FontDescription_Dev*>(desc); +} +PP_FontDescription_Dev* BrowserFontDescToFontDesc( + PP_BrowserFont_Trusted_Description* desc) { + return reinterpret_cast<PP_FontDescription_Dev*>(desc); +} +PP_FontMetrics_Dev* BrowserFontMetricsToFontMetrics( + PP_BrowserFont_Trusted_Metrics* metrics) { + return reinterpret_cast<PP_FontMetrics_Dev*>(metrics); +} +const PP_TextRun_Dev* BrowserFontTextRunToFontTextRun( + const PP_BrowserFont_Trusted_TextRun* run) { + return reinterpret_cast<const PP_TextRun_Dev*>(run); +} + +} // namespace + +// BrowserFontDescription ------------------------------------------------------ + +BrowserFontDescription::BrowserFontDescription() { + pp_font_description_.face = face_.pp_var(); + set_family(PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT); + set_size(0); + set_weight(PP_BROWSERFONT_TRUSTED_WEIGHT_NORMAL); + set_italic(false); + set_small_caps(false); + set_letter_spacing(0); + set_word_spacing(0); +} + +BrowserFontDescription::BrowserFontDescription( + const BrowserFontDescription& other) { + set_face(other.face()); + set_family(other.family()); + set_size(other.size()); + set_weight(other.weight()); + set_italic(other.italic()); + set_small_caps(other.small_caps()); + set_letter_spacing(other.letter_spacing()); + set_word_spacing(other.word_spacing()); +} + +BrowserFontDescription::~BrowserFontDescription() { +} + +BrowserFontDescription& BrowserFontDescription::operator=( + const BrowserFontDescription& other) { + pp_font_description_ = other.pp_font_description_; + + // Be careful about the refcount of the string, the copy that operator= made + // above didn't copy a ref. + pp_font_description_.face = PP_MakeUndefined(); + set_face(other.face()); + + return *this; +} + +// BrowserFontTextRun ---------------------------------------------------------- + +BrowserFontTextRun::BrowserFontTextRun() { + pp_text_run_.text = text_.pp_var(); + pp_text_run_.rtl = PP_FALSE; + pp_text_run_.override_direction = PP_FALSE; +} + +BrowserFontTextRun::BrowserFontTextRun(const std::string& text, + bool rtl, + bool override_direction) + : text_(text) { + pp_text_run_.text = text_.pp_var(); + pp_text_run_.rtl = PP_FromBool(rtl); + pp_text_run_.override_direction = PP_FromBool(override_direction); +} + +BrowserFontTextRun::BrowserFontTextRun(const BrowserFontTextRun& other) + : text_(other.text_) { + pp_text_run_.text = text_.pp_var(); + pp_text_run_.rtl = other.pp_text_run_.rtl; + pp_text_run_.override_direction = other.pp_text_run_.override_direction; +} + +BrowserFontTextRun::~BrowserFontTextRun() { +} + +BrowserFontTextRun& BrowserFontTextRun::operator=( + const BrowserFontTextRun& other) { + pp_text_run_ = other.pp_text_run_; + text_ = other.text_; + pp_text_run_.text = text_.pp_var(); + return *this; +} + +// BrowserFont_Trusted --------------------------------------------------------- + +BrowserFont_Trusted::BrowserFont_Trusted() : Resource() { +} + +BrowserFont_Trusted::BrowserFont_Trusted(PP_Resource resource) + : Resource(resource) { +} + +BrowserFont_Trusted::BrowserFont_Trusted( + Instance* instance, + const BrowserFontDescription& description) { + if (has_interface<PPB_BrowserFont_Trusted>()) { + PassRefFromConstructor(get_interface<PPB_BrowserFont_Trusted>()->Create( + instance->pp_instance(), + &description.pp_font_description())); + } else if (!has_interface<PPB_Font_Dev>()) { + PassRefFromConstructor(get_interface<PPB_Font_Dev>()->Create( + instance->pp_instance(), + BrowserFontDescToFontDesc(&description.pp_font_description()))); + } +} + +BrowserFont_Trusted::BrowserFont_Trusted(const BrowserFont_Trusted& other) + : Resource(other) { +} + +BrowserFont_Trusted& BrowserFont_Trusted::operator=( + const BrowserFont_Trusted& other) { + Resource::operator=(other); + return *this; +} + +// static +Var BrowserFont_Trusted::GetFontFamilies(Instance* instance) { + if (!has_interface<PPB_Font_Dev>()) + return Var(); + return Var(Var::PassRef(), + get_interface<PPB_Font_Dev>()->GetFontFamilies( + instance->pp_instance())); +} + +bool BrowserFont_Trusted::Describe( + BrowserFontDescription* description, + PP_BrowserFont_Trusted_Metrics* metrics) const { + // Be careful with ownership of the |face| string. It will come back with + // a ref of 1, which we want to assign to the |face_| member of the C++ class. + if (has_interface<PPB_BrowserFont_Trusted>()) { + if (!get_interface<PPB_BrowserFont_Trusted>()->Describe( + pp_resource(), &description->pp_font_description_, metrics)) + return false; + } else if (!has_interface<PPB_Font_Dev>()) { + if (!get_interface<PPB_Font_Dev>()->Describe( + pp_resource(), + BrowserFontDescToFontDesc(&description->pp_font_description_), + BrowserFontMetricsToFontMetrics(metrics))) + return false; + } + description->face_ = Var(Var::PassRef(), + description->pp_font_description_.face); + return true; +} + +bool BrowserFont_Trusted::DrawTextAt(ImageData* dest, + const BrowserFontTextRun& text, + const Point& position, + uint32_t color, + const Rect& clip, + bool image_data_is_opaque) const { + if (has_interface<PPB_BrowserFont_Trusted>()) { + return PP_ToBool(get_interface<PPB_BrowserFont_Trusted>()->DrawTextAt( + pp_resource(), + dest->pp_resource(), + &text.pp_text_run(), + &position.pp_point(), + color, + &clip.pp_rect(), + PP_FromBool(image_data_is_opaque))); + } else if (!has_interface<PPB_Font_Dev>()) { + return PP_ToBool(get_interface<PPB_Font_Dev>()->DrawTextAt( + pp_resource(), + dest->pp_resource(), + BrowserFontTextRunToFontTextRun(&text.pp_text_run()), + &position.pp_point(), + color, + &clip.pp_rect(), + PP_FromBool(image_data_is_opaque))); + } + return false; +} + +int32_t BrowserFont_Trusted::MeasureText(const BrowserFontTextRun& text) const { + if (has_interface<PPB_BrowserFont_Trusted>()) { + return get_interface<PPB_BrowserFont_Trusted>()->MeasureText( + pp_resource(), + &text.pp_text_run()); + } else if (!has_interface<PPB_Font_Dev>()) { + return get_interface<PPB_Font_Dev>()->MeasureText( + pp_resource(), + BrowserFontTextRunToFontTextRun(&text.pp_text_run())); + } + return -1; +} + +uint32_t BrowserFont_Trusted::CharacterOffsetForPixel( + const BrowserFontTextRun& text, + int32_t pixel_position) const { + if (has_interface<PPB_BrowserFont_Trusted>()) { + return get_interface<PPB_BrowserFont_Trusted>()->CharacterOffsetForPixel( + pp_resource(), + &text.pp_text_run(), + pixel_position); + } else if (!has_interface<PPB_Font_Dev>()) { + return get_interface<PPB_Font_Dev>()->CharacterOffsetForPixel( + pp_resource(), + BrowserFontTextRunToFontTextRun(&text.pp_text_run()), + pixel_position); + } + return 0; +} + +int32_t BrowserFont_Trusted::PixelOffsetForCharacter( + const BrowserFontTextRun& text, + uint32_t char_offset) const { + if (has_interface<PPB_BrowserFont_Trusted>()) { + return get_interface<PPB_BrowserFont_Trusted>()->PixelOffsetForCharacter( + pp_resource(), + &text.pp_text_run(), + char_offset); + } else if (!has_interface<PPB_Font_Dev>()) { + return get_interface<PPB_Font_Dev>()->PixelOffsetForCharacter( + pp_resource(), + BrowserFontTextRunToFontTextRun(&text.pp_text_run()), + char_offset); + } + return 0; +} + +bool BrowserFont_Trusted::DrawSimpleText( + ImageData* dest, + const std::string& text, + const Point& position, + uint32_t color, + bool image_data_is_opaque) const { + return DrawTextAt(dest, BrowserFontTextRun(text), position, color, + Rect(dest->size()), image_data_is_opaque); +} + +int32_t BrowserFont_Trusted::MeasureSimpleText(const std::string& text) const { + return MeasureText(BrowserFontTextRun(text)); +} + +} // namespace pp diff --git a/ppapi/cpp/trusted/browser_font_trusted.h b/ppapi/cpp/trusted/browser_font_trusted.h new file mode 100644 index 0000000..fc2d801 --- /dev/null +++ b/ppapi/cpp/trusted/browser_font_trusted.h @@ -0,0 +1,147 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_TRUSTED_BROWSER_FONT_TRUSTED_H_ +#define PPAPI_CPP_TRUSTED_BROWSER_FONT_TRUSTED_H_ + +#include <string> + +#include "ppapi/c/trusted/ppb_browser_font_trusted.h" +#include "ppapi/cpp/resource.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +class ImageData; +class Instance; +class Point; +class Rect; + +// BrowserFontDescription ------------------------------------------------------ + +class BrowserFontDescription { + public: + BrowserFontDescription(); + BrowserFontDescription(const BrowserFontDescription& other); + ~BrowserFontDescription(); + + BrowserFontDescription& operator=(const BrowserFontDescription& other); + + const PP_BrowserFont_Trusted_Description& pp_font_description() const { + return pp_font_description_; + } + + Var face() const { return face_; } + void set_face(const Var& face) { + face_ = face; + pp_font_description_.face = face_.pp_var(); + } + + PP_BrowserFont_Trusted_Family family() const { + return pp_font_description_.family; + } + void set_family(PP_BrowserFont_Trusted_Family f) { + pp_font_description_.family = f; + } + + uint32_t size() const { return pp_font_description_.size; } + void set_size(uint32_t s) { pp_font_description_.size = s; } + + PP_BrowserFont_Trusted_Weight weight() const { + return pp_font_description_.weight; + } + void set_weight(PP_BrowserFont_Trusted_Weight w) { + pp_font_description_.weight = w; + } + + bool italic() const { return PP_ToBool(pp_font_description_.italic); } + void set_italic(bool i) { pp_font_description_.italic = PP_FromBool(i); } + + bool small_caps() const { + return PP_ToBool(pp_font_description_.small_caps); + } + void set_small_caps(bool s) { + pp_font_description_.small_caps = PP_FromBool(s); + } + + int letter_spacing() const { return pp_font_description_.letter_spacing; } + void set_letter_spacing(int s) { pp_font_description_.letter_spacing = s; } + + int word_spacing() const { return pp_font_description_.word_spacing; } + void set_word_spacing(int w) { pp_font_description_.word_spacing = w; } + + private: + friend class BrowserFont_Trusted; + + Var face_; // Manages memory for pp_font_description_.face + PP_BrowserFont_Trusted_Description pp_font_description_; +}; + +// BrowserFontTextRun ---------------------------------------------------------- + +class BrowserFontTextRun { + public: + BrowserFontTextRun(); + BrowserFontTextRun(const std::string& text, + bool rtl = false, + bool override_direction = false); + BrowserFontTextRun(const BrowserFontTextRun& other); + ~BrowserFontTextRun(); + + BrowserFontTextRun& operator=(const BrowserFontTextRun& other); + + const PP_BrowserFont_Trusted_TextRun& pp_text_run() const { + return pp_text_run_; + } + + private: + Var text_; // Manages memory for the reference in pp_text_run_. + PP_BrowserFont_Trusted_TextRun pp_text_run_; +}; + +// BrowserFont_Trusted --------------------------------------------------------- + +// Provides access to system fonts. +class BrowserFont_Trusted : public Resource { + public: + // Creates an is_null() Font object. + BrowserFont_Trusted(); + + explicit BrowserFont_Trusted(PP_Resource resource); + BrowserFont_Trusted(Instance* instance, + const BrowserFontDescription& description); + BrowserFont_Trusted(const BrowserFont_Trusted& other); + + BrowserFont_Trusted& operator=(const BrowserFont_Trusted& other); + + // PPB_Font methods: + static Var GetFontFamilies(Instance* instance); + bool Describe(BrowserFontDescription* description, + PP_BrowserFont_Trusted_Metrics* metrics) const; + bool DrawTextAt(ImageData* dest, + const BrowserFontTextRun& text, + const Point& position, + uint32_t color, + const Rect& clip, + bool image_data_is_opaque) const; + int32_t MeasureText(const BrowserFontTextRun& text) const; + uint32_t CharacterOffsetForPixel(const BrowserFontTextRun& text, + int32_t pixel_position) const; + int32_t PixelOffsetForCharacter(const BrowserFontTextRun& text, + uint32_t char_offset) const; + + // Convenience function that assumes a left-to-right string with no clipping. + bool DrawSimpleText(ImageData* dest, + const std::string& text, + const Point& position, + uint32_t color, + bool image_data_is_opaque = false) const; + + // Convenience function that assumes a left-to-right string. + int32_t MeasureSimpleText(const std::string& text) const; +}; + +} // namespace pp + +#endif // PPAPI_CPP_TRUSTED_BROWSER_FONT_TRUSTED_H_ diff --git a/ppapi/example/example.cc b/ppapi/example/example.cc index 6ba7983..8319d49 100644 --- a/ppapi/example/example.cc +++ b/ppapi/example/example.cc @@ -31,7 +31,6 @@ #include "ppapi/cpp/url_loader.h" #include "ppapi/cpp/url_request_info.h" #include "ppapi/cpp/var.h" -#include "ppapi/cpp/view.h" #include "ppapi/utility/completion_callback_factory.h" static const int kStepsPerCircle = 800; @@ -99,10 +98,10 @@ class MyFetcher { callback_factory_.Initialize(this); } - void Start(pp::InstancePrivate& instance, + void Start(const pp::InstancePrivate& instance, const pp::Var& url, MyFetcherClient* client) { - pp::URLRequestInfo request(&instance); + pp::URLRequestInfo request; request.SetURL(url); request.SetMethod("GET"); @@ -168,11 +167,11 @@ class MyInstance : public pp::InstancePrivate, public MyFetcherClient { : pp::InstancePrivate(instance), time_at_last_check_(0.0), fetcher_(NULL), + width_(0), + height_(0), animation_counter_(0), print_settings_valid_(false), - showing_custom_cursor_(false), - cursor_dimension_(50), - expanding_cursor_(false) { + showing_custom_cursor_(false) { RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); } @@ -220,10 +219,11 @@ class MyInstance : public pp::InstancePrivate, public MyFetcherClient { return pp::VarPrivate(this, new MyScriptableObject(this)); } - pp::ImageData PaintImage(const pp::Size& size) { - pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, false); + pp::ImageData PaintImage(int width, int height) { + pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, + pp::Size(width, height), false); if (image.is_null()) { - printf("Couldn't allocate the image data."); + printf("Couldn't allocate the image data: %d, %d\n", width, height); return image; } @@ -242,8 +242,7 @@ class MyInstance : public pp::InstancePrivate, public MyFetcherClient { float radians = static_cast<float>(animation_counter_) / kStepsPerCircle * 2 * 3.14159265358979F; - float radius = - static_cast<float>(std::min(size.width(), size.height())) / 2.0f - 3.0f; + float radius = static_cast<float>(std::min(width, height)) / 2.0f - 3.0f; int x = static_cast<int>(cos(radians) * radius + radius + 2); int y = static_cast<int>(sin(radians) * radius + radius + 2); @@ -253,25 +252,27 @@ class MyInstance : public pp::InstancePrivate, public MyFetcherClient { } void Paint() { - pp::ImageData image = PaintImage(device_context_.size()); + pp::ImageData image = PaintImage(width_, height_); if (!image.is_null()) { device_context_.ReplaceContents(&image); device_context_.Flush(pp::CompletionCallback(&FlushCallback, this)); } else { - printf("NullImage\n"); + printf("NullImage: %d, %d\n", width_, height_); } } - virtual void DidChangeView(const pp::View& view) { + virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { Log(PP_LOGLEVEL_LOG, "DidChangeView"); - if (view.GetRect().size() == current_view_.GetRect().size()) + if (position.size().width() == width_ && + position.size().height() == height_) return; // We don't care about the position, only the size. - current_view_ = view; + width_ = position.size().width(); + height_ = position.size().height(); printf("DidChangeView relevant change: width=%d height:%d\n", - view.GetRect().width(), view.GetRect().height()); + width_, height_); - device_context_ = pp::Graphics2D(this, view.GetRect().size(), false); + device_context_ = pp::Graphics2D(this, pp::Size(width_, height_), false); if (!BindGraphics(device_context_)) { printf("Couldn't bind the device context\n"); return; @@ -328,8 +329,16 @@ int gettimeofday(struct timeval *tv, struct timezone*) { } // Print interfaces. - virtual uint32_t QuerySupportedPrintOutputFormats() { - return PP_PRINTOUTPUTFORMAT_RASTER; + // TODO(mball,dmichael) Replace this with the PPP_PRINTING_DEV_USE_0_4 version + virtual PP_PrintOutputFormat_Dev* QuerySupportedPrintOutputFormats( + uint32_t* format_count) { + pp::Memory_Dev memory; + PP_PrintOutputFormat_Dev* format = + static_cast<PP_PrintOutputFormat_Dev*>( + memory.MemAlloc(sizeof(PP_PrintOutputFormat_Dev))); + *format = PP_PRINTOUTPUTFORMAT_RASTER; + *format_count = 1; + return format; } virtual int32_t PrintBegin(const PP_PrintSettings_Dev& print_settings) { @@ -356,30 +365,25 @@ int gettimeofday(struct timeval *tv, struct timezone*) { return pp::Resource(); } - pp::Size size(static_cast<int>( - (print_settings_.printable_area.size.width / 72.0) * - print_settings_.dpi), - static_cast<int>( - (print_settings_.printable_area.size.height / 72.0) * - print_settings_.dpi)); - return PaintImage(size); + int width = static_cast<int>( + (print_settings_.printable_area.size.width / 72.0) * + print_settings_.dpi); + int height = static_cast<int>( + (print_settings_.printable_area.size.height / 72.0) * + print_settings_.dpi); + + return PaintImage(width, height); } virtual void PrintEnd() { print_settings_valid_ = false; } - virtual bool IsScalingDisabled() { - return false; - } - void OnFlush() { if (animation_counter_ % kStepsPerCircle == 0) UpdateFps(); animation_counter_++; Paint(); - if (showing_custom_cursor_) - SetCursor(); } private: @@ -427,11 +431,6 @@ int gettimeofday(struct timeval *tv, struct timezone*) { } void ToggleCursor() { - showing_custom_cursor_ = !showing_custom_cursor_; - SetCursor(); - } - - void SetCursor() { const PPB_CursorControl_Dev* cursor_control = reinterpret_cast<const PPB_CursorControl_Dev*>( pp::Module::Get()->GetBrowserInterface( @@ -439,26 +438,20 @@ int gettimeofday(struct timeval *tv, struct timezone*) { if (!cursor_control) return; - if (!showing_custom_cursor_) { + if (showing_custom_cursor_) { cursor_control->SetCursor(pp_instance(), PP_CURSORTYPE_POINTER, 0, NULL); } else { pp::ImageData image_data(this, pp::ImageData::GetNativeImageDataFormat(), - pp::Size(cursor_dimension_, cursor_dimension_), - false); - FillRect(&image_data, 0, 0, cursor_dimension_, cursor_dimension_, + pp::Size(50, 50), false); + FillRect(&image_data, 0, 0, 50, 50, image_data.format() == PP_IMAGEDATAFORMAT_BGRA_PREMUL ? 0x80800000 : 0x80000080); - pp::Point hot_spot(cursor_dimension_ / 2, cursor_dimension_ / 2); + pp::Point hot_spot(0, 0); cursor_control->SetCursor(pp_instance(), PP_CURSORTYPE_CUSTOM, image_data.pp_resource(), &hot_spot.pp_point()); - if (expanding_cursor_) { - if (++cursor_dimension_ >= 50) - expanding_cursor_ = false; - } else { - if (--cursor_dimension_ <= 5) - expanding_cursor_ = true; - } } + + showing_custom_cursor_ = !showing_custom_cursor_; } pp::Var console_; @@ -466,18 +459,17 @@ int gettimeofday(struct timeval *tv, struct timezone*) { double time_at_last_check_; - pp::View current_view_; - MyFetcher* fetcher_; + int width_; + int height_; + // Incremented for each flush we get. int animation_counter_; bool print_settings_valid_; PP_PrintSettings_Dev print_settings_; bool showing_custom_cursor_; - int cursor_dimension_; - bool expanding_cursor_; }; void FlushCallback(void* data, int32_t result) { diff --git a/ppapi/examples/font/simple_font.cc b/ppapi/examples/font/simple_font.cc index 94b0ecc..b66c79e 100644 --- a/ppapi/examples/font/simple_font.cc +++ b/ppapi/examples/font/simple_font.cc @@ -5,13 +5,13 @@ #include <stdio.h> #include "ppapi/cpp/completion_callback.h" -#include "ppapi/cpp/dev/font_dev.h" #include "ppapi/cpp/graphics_2d.h" #include "ppapi/cpp/image_data.h" #include "ppapi/cpp/instance.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/rect.h" #include "ppapi/cpp/size.h" +#include "ppapi/cpp/trusted/browser_font_trusted.h" static void DummyCompletionCallback(void* /*user_data*/, int32_t /*result*/) { } @@ -31,50 +31,50 @@ class MyInstance : public pp::Instance { pp::Graphics2D graphics(this, last_size_, false); BindGraphics(graphics); - pp::FontDescription_Dev desc; - desc.set_family(PP_FONTFAMILY_SANSSERIF); + pp::BrowserFontDescription desc; + desc.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF); desc.set_size(100); - pp::Font_Dev font(this, desc); + pp::BrowserFont_Trusted font(this, desc); // Draw some large, alpha blended text, including Arabic shaping. pp::Rect text_clip(position.size()); // Use entire bounds for clip. font.DrawTextAt(&image, - pp::TextRun_Dev("\xD9\x85\xD8\xB1\xD8\xAD\xD8\xA8\xD8\xA7\xE2\x80\x8E", - true, true), + pp::BrowserFontTextRun( + "\xD9\x85\xD8\xB1\xD8\xAD\xD8\xA8\xD8\xA7\xE2\x80\x8E", true, true), pp::Point(20, 100), 0x80008000, clip, false); // Draw the default font names and sizes. int y = 160; { - pp::FontDescription_Dev desc; - pp::Font_Dev default_font(this, desc); + pp::BrowserFontDescription desc; + pp::BrowserFont_Trusted default_font(this, desc); default_font.DrawSimpleText( &image, DescribeFont(default_font, "Default font"), pp::Point(10, y), 0xFF000000); y += 20; } { - pp::FontDescription_Dev desc; - desc.set_family(PP_FONTFAMILY_SERIF); - pp::Font_Dev serif_font(this, desc); + pp::BrowserFontDescription desc; + desc.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SERIF); + pp::BrowserFont_Trusted serif_font(this, desc); serif_font.DrawSimpleText( &image, DescribeFont(serif_font, "Serif font"), pp::Point(10, y), 0xFF000000); y += 20; } { - pp::FontDescription_Dev desc; - desc.set_family(PP_FONTFAMILY_SANSSERIF); - pp::Font_Dev sans_serif_font(this, desc); + pp::BrowserFontDescription desc; + desc.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF); + pp::BrowserFont_Trusted sans_serif_font(this, desc); sans_serif_font.DrawSimpleText( &image, DescribeFont(sans_serif_font, "Sans serif font"), pp::Point(10, y), 0xFF000000); y += 20; } { - pp::FontDescription_Dev desc; - desc.set_family(PP_FONTFAMILY_MONOSPACE); - pp::Font_Dev monospace_font(this, desc); + pp::BrowserFontDescription desc; + desc.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE); + pp::BrowserFont_Trusted monospace_font(this, desc); monospace_font.DrawSimpleText( &image, DescribeFont(monospace_font, "Monospace font"), pp::Point(10, y), 0xFF000000); @@ -87,9 +87,10 @@ class MyInstance : public pp::Instance { private: // Returns a string describing the given font, using the given title. - std::string DescribeFont(const pp::Font_Dev& font, const char* title) { - pp::FontDescription_Dev desc; - PP_FontMetrics_Dev metrics; + std::string DescribeFont(const pp::BrowserFont_Trusted& font, + const char* title) { + pp::BrowserFontDescription desc; + PP_BrowserFont_Trusted_Metrics metrics; font.Describe(&desc, &metrics); char buf[256]; diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 03d26ab..7b858c7 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -91,8 +91,6 @@ 'proxy/ppb_flash_message_loop_proxy.h', 'proxy/ppb_flash_net_connector_proxy.cc', 'proxy/ppb_flash_net_connector_proxy.h', - 'proxy/ppb_font_proxy.cc', - 'proxy/ppb_font_proxy.h', 'proxy/ppb_graphics_2d_proxy.cc', 'proxy/ppb_graphics_2d_proxy.h', 'proxy/ppb_graphics_3d_proxy.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index eb0fc4b..b6c3b62 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -122,16 +122,14 @@ 'shared_impl/var.h', 'shared_impl/var_tracker.cc', 'shared_impl/var_tracker.h', - 'shared_impl/webkit_forwarding.cc', - 'shared_impl/webkit_forwarding.h', # TODO(viettrungluu): Split these out; it won't be used in NaCl. 'shared_impl/private/net_address_private_impl.cc', 'shared_impl/private/net_address_private_impl.h', + 'shared_impl/private/ppb_browser_font_trusted_shared.cc', + 'shared_impl/private/ppb_browser_font_trusted_shared.h', 'shared_impl/private/ppb_char_set_shared.cc', 'shared_impl/private/ppb_char_set_shared.h', - 'shared_impl/private/ppb_font_shared.cc', - 'shared_impl/private/ppb_font_shared.h', 'shared_impl/private/tcp_socket_private_impl.cc', 'shared_impl/private/tcp_socket_private_impl.h', @@ -150,6 +148,8 @@ 'thunk/ppb_audio_trusted_thunk.cc', 'thunk/ppb_broker_api.h', 'thunk/ppb_broker_thunk.cc', + 'thunk/ppb_browser_font_trusted_api.h', + 'thunk/ppb_browser_font_trusted_thunk.cc', 'thunk/ppb_buffer_api.h', 'thunk/ppb_buffer_thunk.cc', 'thunk/ppb_buffer_trusted_api.h', @@ -183,8 +183,6 @@ 'thunk/ppb_flash_message_loop_thunk.cc', 'thunk/ppb_flash_net_connector_api.h', 'thunk/ppb_flash_net_connector_thunk.cc', - 'thunk/ppb_font_api.h', - 'thunk/ppb_font_thunk.cc', 'thunk/ppb_fullscreen_thunk.cc', 'thunk/ppb_gamepad_thunk.cc', 'thunk/ppb_gles_chromium_texture_mapping_thunk.cc', diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi index 5e9be70..1fdf423 100644 --- a/ppapi/ppapi_sources.gypi +++ b/ppapi/ppapi_sources.gypi @@ -113,6 +113,7 @@ # Trusted interfaces. 'c/trusted/ppb_audio_trusted.h', 'c/trusted/ppb_broker_trusted.h', + 'c/private/ppb_browser_font_trusted.h', 'c/trusted/ppb_buffer_trusted.h', 'c/trusted/ppb_file_chooser_trusted.h', 'c/trusted/ppb_file_io_trusted.h', @@ -258,6 +259,8 @@ 'cpp/private/var_private.h', # Trusted interfaces. + 'cpp/trusted/browser_font_trusted.cc', + 'cpp/trusted/browser_font_trusted.h', 'cpp/trusted/file_chooser_trusted.cc', 'cpp/trusted/file_chooser_trusted.h', 'cpp/trusted/file_io_trusted.cc', @@ -338,6 +341,8 @@ 'tests/test_audio_config.h', 'tests/test_broker.cc', 'tests/test_broker.h', + 'tests/test_browser_font.cc', + 'tests/test_browser_font.h', 'tests/test_buffer.cc', 'tests/test_buffer.h', 'tests/test_c_includes.c', diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index ce456ddc..0ff81c2e 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -60,6 +60,7 @@ #include "ppapi/c/private/ppb_tcp_socket_private.h" #include "ppapi/c/private/ppb_udp_socket_private.h" #include "ppapi/c/trusted/ppb_broker_trusted.h" +#include "ppapi/c/trusted/ppb_browser_font_trusted.h" #include "ppapi/c/trusted/ppb_char_set_trusted.h" #include "ppapi/c/trusted/ppb_file_io_trusted.h" #include "ppapi/c/trusted/ppb_url_loader_trusted.h" @@ -80,7 +81,6 @@ #include "ppapi/proxy/ppb_flash_message_loop_proxy.h" #include "ppapi/proxy/ppb_flash_net_connector_proxy.h" #include "ppapi/proxy/ppb_flash_proxy.h" -#include "ppapi/proxy/ppb_font_proxy.h" #include "ppapi/proxy/ppb_graphics_2d_proxy.h" #include "ppapi/proxy/ppb_graphics_3d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc index bfa7917..3788d40 100644 --- a/ppapi/proxy/plugin_dispatcher.cc +++ b/ppapi/proxy/plugin_dispatcher.cc @@ -21,7 +21,6 @@ #include "ppapi/proxy/plugin_var_serialization_rules.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_cursor_control_proxy.h" -#include "ppapi/proxy/ppb_font_proxy.h" #include "ppapi/proxy/ppb_instance_proxy.h" #include "ppapi/proxy/ppp_class_proxy.h" #include "ppapi/proxy/resource_creation_proxy.h" diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 04b812d..1f47a17 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -843,10 +843,6 @@ IPC_MESSAGE_CONTROL3(PpapiHostMsg_PPBUDPSocket_SendTo, IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBUDPSocket_Close, uint32 /* socket_id */) -// PPB_Font. -IPC_SYNC_MESSAGE_CONTROL0_1(PpapiHostMsg_PPBFont_GetFontFamilies, - std::string /* result */) - // PPB_Graphics2D. IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBGraphics2D_Create, PP_Instance /* instance */, @@ -938,6 +934,8 @@ IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBInstance_ExecuteScript, IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBInstance_GetDefaultCharSet, PP_Instance /* instance */, ppapi::proxy::SerializedVar /* result */) +IPC_SYNC_MESSAGE_CONTROL0_1(PpapiHostMsg_PPBInstance_GetFontFamilies, + std::string /* result */) IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBInstance_SetFullscreen, PP_Instance /* instance */, PP_Bool /* fullscreen */, diff --git a/ppapi/proxy/ppb_font_proxy.cc b/ppapi/proxy/ppb_font_proxy.cc deleted file mode 100644 index b12c22e..0000000 --- a/ppapi/proxy/ppb_font_proxy.cc +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ppapi/proxy/ppb_font_proxy.h" - -#include "ppapi/c/dev/ppb_font_dev.h" -#include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_globals.h" -#include "ppapi/proxy/plugin_proxy_delegate.h" -#include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/shared_impl/var.h" - -using ppapi::thunk::PPB_Font_FunctionAPI; - -namespace ppapi { -namespace proxy { - -PPB_Font_Proxy::PPB_Font_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { -} - -PPB_Font_Proxy::~PPB_Font_Proxy() { -} - -PPB_Font_FunctionAPI* PPB_Font_Proxy::AsPPB_Font_FunctionAPI() { - return this; -} - -// TODO(ananta) -// This needs to be wired up to the PPAPI plugin code. -PP_Var PPB_Font_Proxy::GetFontFamilies(PP_Instance instance) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return PP_MakeUndefined(); - - // Assume the font families don't change, so we can cache the result globally. - CR_DEFINE_STATIC_LOCAL(std::string, families, ()); - if (families.empty()) { - PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( - new PpapiHostMsg_PPBFont_GetFontFamilies(&families)); - } - - return StringVar::StringToPPVar(families); -} - -bool PPB_Font_Proxy::OnMessageReceived(const IPC::Message& msg) { - // There aren't any font messages. - NOTREACHED(); - return false; -} - -} // namespace proxy -} // namespace ppapi diff --git a/ppapi/proxy/ppb_font_proxy.h b/ppapi/proxy/ppb_font_proxy.h deleted file mode 100644 index 2849f3d..0000000 --- a/ppapi/proxy/ppb_font_proxy.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef PPAPI_PROXY_PPB_FONT_PROXY_H_ -#define PPAPI_PROXY_PPB_FONT_PROXY_H_ - -#include "base/callback_forward.h" -#include "ppapi/proxy/interface_proxy.h" -#include "ppapi/shared_impl/function_group_base.h" -#include "ppapi/shared_impl/host_resource.h" -#include "ppapi/shared_impl/resource.h" -#include "ppapi/thunk/ppb_font_api.h" - -namespace ppapi { -namespace proxy { - -class PPB_Font_Proxy : public InterfaceProxy, - public ppapi::thunk::PPB_Font_FunctionAPI { - public: - explicit PPB_Font_Proxy(Dispatcher* dispatcher); - virtual ~PPB_Font_Proxy(); - - // FunctionGroupBase overrides. - virtual ppapi::thunk::PPB_Font_FunctionAPI* AsPPB_Font_FunctionAPI() OVERRIDE; - - // PPB_Font_FunctionAPI implementation. - virtual PP_Var GetFontFamilies(PP_Instance instance) OVERRIDE; - - // InterfaceProxy implementation. - virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; - - static const ApiID kApiID = API_ID_PPB_FONT; - - private: - DISALLOW_COPY_AND_ASSIGN(PPB_Font_Proxy); -}; - -} // namespace proxy -} // namespace ppapi - -#endif // PPAPI_PROXY_PPB_FONT_PROXY_H_ diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index 7cc33f0..5bdde43 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -12,11 +12,13 @@ #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_proxy_delegate.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" #include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/ppb_url_util_shared.h" #include "ppapi/shared_impl/ppb_view_shared.h" +#include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" @@ -213,6 +215,21 @@ PP_Bool PPB_Instance_Proxy::FlashIsFullscreen(PP_Instance instance) { return data->flash_fullscreen; } +PP_Var PPB_Instance_Proxy::GetFontFamilies(PP_Instance instance) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return PP_MakeUndefined(); + + // Assume the font families don't change, so we can cache the result globally. + CR_DEFINE_STATIC_LOCAL(std::string, families, ()); + if (families.empty()) { + PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( + new PpapiHostMsg_PPBInstance_GetFontFamilies(&families)); + } + + return StringVar::StringToPPVar(families); +} + PP_Bool PPB_Instance_Proxy::SetFullscreen(PP_Instance instance, PP_Bool fullscreen) { PP_Bool result = PP_FALSE; diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h index 71107e4..ba6b2ae 100644 --- a/ppapi/proxy/ppb_instance_proxy.h +++ b/ppapi/proxy/ppb_instance_proxy.h @@ -58,6 +58,7 @@ class PPB_Instance_Proxy : public InterfaceProxy, PP_Bool final_result) OVERRIDE; virtual void SelectedFindResultChanged(PP_Instance instance, int32_t index) OVERRIDE; + virtual PP_Var GetFontFamilies(PP_Instance instance) OVERRIDE; virtual PP_Bool SetFullscreen(PP_Instance instance, PP_Bool fullscreen) OVERRIDE; virtual PP_Bool GetScreenSize(PP_Instance instance, diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 5d8cd4d..731dd60 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -21,7 +21,6 @@ #include "ppapi/proxy/ppb_flash_menu_proxy.h" #include "ppapi/proxy/ppb_flash_message_loop_proxy.h" #include "ppapi/proxy/ppb_flash_net_connector_proxy.h" -#include "ppapi/proxy/ppb_font_proxy.h" #include "ppapi/proxy/ppb_graphics_2d_proxy.h" #include "ppapi/proxy/ppb_graphics_3d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" @@ -37,7 +36,7 @@ #include "ppapi/shared_impl/ppb_input_event_shared.h" #include "ppapi/shared_impl/ppb_resource_array_shared.h" #include "ppapi/shared_impl/ppb_url_request_info_shared.h" -#include "ppapi/shared_impl/private/ppb_font_shared.h" +#include "ppapi/shared_impl/private/ppb_browser_font_trusted_shared.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_image_data_api.h" @@ -105,6 +104,16 @@ PP_Resource ResourceCreationProxy::CreateBroker(PP_Instance instance) { return PPB_Broker_Proxy::CreateProxyResource(instance); } +PP_Resource ResourceCreationProxy::CreateBrowserFont( + PP_Instance instance, + const PP_BrowserFont_Trusted_Description* description) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return 0; + return PPB_BrowserFont_Trusted_Shared::Create( + OBJECT_IS_PROXY, instance, *description, dispatcher->preferences()); +} + PP_Resource ResourceCreationProxy::CreateBuffer(PP_Instance instance, uint32_t size) { return PPB_Buffer_Proxy::CreateProxyResource(instance, size); @@ -155,17 +164,6 @@ PP_Resource ResourceCreationProxy::CreateFlashNetConnector( return PPB_Flash_NetConnector_Proxy::CreateProxyResource(instance); } -PP_Resource ResourceCreationProxy::CreateFontObject( - PP_Instance instance, - const PP_FontDescription_Dev* description) { - PluginDispatcher* dispatcher = - PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return 0; - return PPB_Font_Shared::Create(OBJECT_IS_PROXY, instance, *description, - dispatcher->preferences()); -} - PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance instance, const PP_Size& size, PP_Bool is_always_opaque) { diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index d28f153..f508e42 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -53,6 +53,9 @@ class ResourceCreationProxy : public InterfaceProxy, void* user_data) OVERRIDE; virtual PP_Resource CreateAudioInputTrusted(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateBroker(PP_Instance instance) OVERRIDE; + virtual PP_Resource CreateBrowserFont( + PP_Instance instance, + const PP_BrowserFont_Trusted_Description* description) OVERRIDE; virtual PP_Resource CreateBuffer(PP_Instance instance, uint32_t size) OVERRIDE; virtual PP_Resource CreateDirectoryReader(PP_Resource directory_ref) OVERRIDE; @@ -69,9 +72,6 @@ class ResourceCreationProxy : public InterfaceProxy, const PP_Flash_Menu* menu_data) OVERRIDE; virtual PP_Resource CreateFlashMessageLoop(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateFlashNetConnector(PP_Instance instance) OVERRIDE; - virtual PP_Resource CreateFontObject( - PP_Instance instance, - const PP_FontDescription_Dev* description) OVERRIDE; virtual PP_Resource CreateGraphics2D(PP_Instance pp_instance, const PP_Size& size, PP_Bool is_always_opaque) OVERRIDE; diff --git a/ppapi/shared_impl/private/ppb_browser_font_trusted_shared.cc b/ppapi/shared_impl/private/ppb_browser_font_trusted_shared.cc new file mode 100644 index 0000000..ab7c45a --- /dev/null +++ b/ppapi/shared_impl/private/ppb_browser_font_trusted_shared.cc @@ -0,0 +1,325 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/shared_impl/private/ppb_browser_font_trusted_shared.h" + +#include "base/string_util.h" +#include "base/utf_string_conversions.h" +#include "ppapi/c/dev/ppb_font_dev.h" +#include "ppapi/shared_impl/ppapi_preferences.h" +#include "ppapi/shared_impl/var.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_image_data_api.h" +#include "ppapi/thunk/thunk.h" +#include "skia/ext/platform_canvas.h" +#include "third_party/skia/include/core/SkRect.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoint.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFont.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFontDescription.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextRun.h" + +using ppapi::StringVar; +using ppapi::thunk::EnterResourceNoLock; +using ppapi::thunk::PPB_ImageData_API; +using WebKit::WebFloatPoint; +using WebKit::WebFloatRect; +using WebKit::WebFont; +using WebKit::WebFontDescription; +using WebKit::WebRect; +using WebKit::WebTextRun; +using WebKit::WebCanvas; + +namespace ppapi { + +namespace { + +bool PPTextRunToWebTextRun(const PP_BrowserFont_Trusted_TextRun& text, + WebTextRun* run) { + StringVar* text_string = StringVar::FromPPVar(text.text); + if (!text_string) + return false; + + *run = WebTextRun(UTF8ToUTF16(text_string->value()), + PP_ToBool(text.rtl), + PP_ToBool(text.override_direction)); + return true; +} + +// The PP_* version lacks "None", so is just one value shifted from the +// WebFontDescription version. These values are checked in +// PPFontDescToWebFontDesc to make sure the conversion is correct. This is a +// macro so it can also be used in the COMPILE_ASSERTS. +#define PP_FAMILY_TO_WEB_FAMILY(f) \ + static_cast<WebFontDescription::GenericFamily>(f + 1) + +// Assumes the given PP_FontDescription has been validated. +WebFontDescription PPFontDescToWebFontDesc( + const PP_BrowserFont_Trusted_Description& font, + const Preferences& prefs) { + // Verify that the enums match so we can just static cast. + COMPILE_ASSERT(static_cast<int>(WebFontDescription::Weight100) == + static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_100), + FontWeight100); + COMPILE_ASSERT(static_cast<int>(WebFontDescription::Weight900) == + static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_900), + FontWeight900); + COMPILE_ASSERT(WebFontDescription::GenericFamilyStandard == + PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_DEFAULT), + StandardFamily); + COMPILE_ASSERT(WebFontDescription::GenericFamilySerif == + PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_SERIF), + SerifFamily); + COMPILE_ASSERT(WebFontDescription::GenericFamilySansSerif == + PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_SANSSERIF), + SansSerifFamily); + COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace == + PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_MONOSPACE), + MonospaceFamily); + + StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null. + + WebFontDescription result; + string16 resolved_family; + if (!face_name || face_name->value().empty()) { + // Resolve the generic family. + switch (font.family) { + case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: + resolved_family = prefs.serif_font_family; + break; + case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: + resolved_family = prefs.sans_serif_font_family; + break; + case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: + resolved_family = prefs.fixed_font_family; + break; + case PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT: + default: + resolved_family = prefs.standard_font_family; + break; + } + } else { + // Use the exact font. + resolved_family = UTF8ToUTF16(face_name->value()); + } + result.family = resolved_family; + + result.genericFamily = PP_FAMILY_TO_WEB_FAMILY(font.family); + + if (font.size == 0) { + // Resolve the default font size, using the resolved family to see if + // we should use the fixed or regular font size. It's difficult at this + // level to detect if the requested font is fixed width, so we only apply + // the alternate font size to the default fixed font family. + if (StringToLowerASCII(resolved_family) == + StringToLowerASCII(prefs.fixed_font_family)) + result.size = static_cast<float>(prefs.default_fixed_font_size); + else + result.size = static_cast<float>(prefs.default_font_size); + } else { + // Use the exact size. + result.size = static_cast<float>(font.size); + } + + result.italic = font.italic != PP_FALSE; + result.smallCaps = font.small_caps != PP_FALSE; + result.weight = static_cast<WebFontDescription::Weight>(font.weight); + result.letterSpacing = static_cast<short>(font.letter_spacing); + result.wordSpacing = static_cast<short>(font.word_spacing); + return result; +} + +} // namespace + +// static +bool PPB_BrowserFont_Trusted_Shared::IsPPFontDescriptionValid( + const PP_BrowserFont_Trusted_Description& desc) { + // Check validity of string. We can't check the actual text since we could + // be on the wrong thread and don't know if we're in the plugin or the host. + if (desc.face.type != PP_VARTYPE_STRING && + desc.face.type != PP_VARTYPE_UNDEFINED) + return false; + + // Check enum ranges. + if (static_cast<int>(desc.family) < PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT || + static_cast<int>(desc.family) > PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE) + return false; + if (static_cast<int>(desc.weight) < PP_BROWSERFONT_TRUSTED_WEIGHT_100 || + static_cast<int>(desc.weight) > PP_BROWSERFONT_TRUSTED_WEIGHT_900) + return false; + + // Check for excessive sizes which may cause layout to get confused. + if (desc.size > 200) + return false; + + return true; +} + +// static +PP_Resource PPB_BrowserFont_Trusted_Shared::Create( + ResourceObjectType type, + PP_Instance instance, + const PP_BrowserFont_Trusted_Description& description, + const Preferences& prefs) { + if (!PPB_BrowserFont_Trusted_Shared::IsPPFontDescriptionValid(description)) + return 0; + return (new PPB_BrowserFont_Trusted_Shared(type, instance, + description, + prefs))->GetReference(); +} + +PPB_BrowserFont_Trusted_Shared::PPB_BrowserFont_Trusted_Shared( + ResourceObjectType type, + PP_Instance instance, + const PP_BrowserFont_Trusted_Description& desc, + const Preferences& prefs) + : Resource(type, instance), + font_(WebFont::create(PPFontDescToWebFontDesc(desc, prefs))) { +} + +PPB_BrowserFont_Trusted_Shared::~PPB_BrowserFont_Trusted_Shared() { +} + +thunk::PPB_BrowserFont_Trusted_API* +PPB_BrowserFont_Trusted_Shared::AsPPB_BrowserFont_Trusted_API() { + return this; +} + +PP_Bool PPB_BrowserFont_Trusted_Shared::Describe( + PP_BrowserFont_Trusted_Description* description, + PP_BrowserFont_Trusted_Metrics* metrics) { + if (description->face.type != PP_VARTYPE_UNDEFINED) + return PP_FALSE; + + // While converting the other way in PPFontDescToWebFontDesc we validated + // that the enums can be casted. + WebFontDescription web_desc = font_->fontDescription(); + description->face = StringVar::StringToPPVar(UTF16ToUTF8(web_desc.family)); + description->family = + static_cast<PP_BrowserFont_Trusted_Family>(web_desc.genericFamily); + description->size = static_cast<uint32_t>(web_desc.size); + description->weight = static_cast<PP_BrowserFont_Trusted_Weight>( + web_desc.weight); + description->italic = web_desc.italic ? PP_TRUE : PP_FALSE; + description->small_caps = web_desc.smallCaps ? PP_TRUE : PP_FALSE; + description->letter_spacing = static_cast<int32_t>(web_desc.letterSpacing); + description->word_spacing = static_cast<int32_t>(web_desc.wordSpacing); + + metrics->height = font_->height(); + metrics->ascent = font_->ascent(); + metrics->descent = font_->descent(); + metrics->line_spacing = font_->lineSpacing(); + metrics->x_height = static_cast<int32_t>(font_->xHeight()); + + // Convert the string. + return PP_TRUE; +} + +PP_Bool PPB_BrowserFont_Trusted_Shared::DrawTextAt( + PP_Resource image_data, + const PP_BrowserFont_Trusted_TextRun* text, + const PP_Point* position, + uint32_t color, + const PP_Rect* clip, + PP_Bool image_data_is_opaque) { + PP_Bool result = PP_FALSE; + // Get and map the image data we're painting to. + EnterResourceNoLock<PPB_ImageData_API> enter(image_data, true); + if (enter.failed()) + return result; + + PPB_ImageData_API* image = static_cast<PPB_ImageData_API*>( + enter.object()); + skia::PlatformCanvas* canvas = image->GetPlatformCanvas(); + bool needs_unmapping = false; + if (!canvas) { + needs_unmapping = true; + image->Map(); + canvas = image->GetPlatformCanvas(); + if (!canvas) + return result; // Failure mapping. + } + + DrawTextToCanvas(canvas, *text, position, color, clip, image_data_is_opaque); + + if (needs_unmapping) + image->Unmap(); + return PP_TRUE; +} + +int32_t PPB_BrowserFont_Trusted_Shared::MeasureText( + const PP_BrowserFont_Trusted_TextRun* text) { + WebTextRun run; + if (!PPTextRunToWebTextRun(*text, &run)) + return -1; + return font_->calculateWidth(run); +} + +uint32_t PPB_BrowserFont_Trusted_Shared::CharacterOffsetForPixel( + const PP_BrowserFont_Trusted_TextRun* text, + int32_t pixel_position) { + WebTextRun run; + if (!PPTextRunToWebTextRun(*text, &run)) + return -1; + return static_cast<uint32_t>(font_->offsetForPosition( + run, static_cast<float>(pixel_position))); +} + +int32_t PPB_BrowserFont_Trusted_Shared::PixelOffsetForCharacter( + const PP_BrowserFont_Trusted_TextRun* text, + uint32_t char_offset) { + WebTextRun run; + if (!PPTextRunToWebTextRun(*text, &run)) + return -1; + if (char_offset >= run.text.length()) + return -1; + + WebFloatRect rect = font_->selectionRectForText( + run, WebFloatPoint(0.0f, 0.0f), font_->height(), 0, char_offset); + return static_cast<int>(rect.width); +} + +void PPB_BrowserFont_Trusted_Shared::DrawTextToCanvas( + skia::PlatformCanvas* destination, + const PP_BrowserFont_Trusted_TextRun& text, + const PP_Point* position, + uint32_t color, + const PP_Rect* clip, + PP_Bool image_data_is_opaque) { + WebTextRun run; + if (!PPTextRunToWebTextRun(text, &run)) + return; + + // Convert position and clip. + WebFloatPoint web_position(static_cast<float>(position->x), + static_cast<float>(position->y)); + WebRect web_clip; + if (!clip) { + // Use entire canvas. SkCanvas doesn't have a size on it, so we just use + // the current clip bounds. + SkRect skclip; + destination->getClipBounds(&skclip); + web_clip = WebRect(skclip.fLeft, skclip.fTop, skclip.fRight - skclip.fLeft, + skclip.fBottom - skclip.fTop); + } else { + web_clip = WebRect(clip->point.x, clip->point.y, + clip->size.width, clip->size.height); + } + +#if WEBKIT_USING_SKIA + WebCanvas* canvas = destination; +#elif WEBKIT_USING_CG + WebCanvas* canvas = skia::GetBitmapContext(skia::GetTopDevice(*destination)); +#else + NOTIMPLEMENTED(); + return; +#endif + font_->drawText(canvas, run, web_position, color, web_clip, + PP_ToBool(image_data_is_opaque)); +} + +} // namespace ppapi + diff --git a/ppapi/shared_impl/private/ppb_browser_font_trusted_shared.h b/ppapi/shared_impl/private/ppb_browser_font_trusted_shared.h new file mode 100644 index 0000000..e8a2bb5 --- /dev/null +++ b/ppapi/shared_impl/private/ppb_browser_font_trusted_shared.h @@ -0,0 +1,91 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_SHARED_IMPL_PRIVATE_PPB_BROWSER_FONT_TRUSTED_SHARED_H_ +#define PPAPI_SHARED_IMPL_PRIVATE_PPB_BROWSER_FONT_TRUSTED_SHARED_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/pp_stdint.h" +#include "ppapi/shared_impl/ppapi_preferences.h" +#include "ppapi/shared_impl/ppapi_shared_export.h" +#include "ppapi/shared_impl/resource.h" +#include "ppapi/thunk/ppb_browser_font_trusted_api.h" + +namespace skia { +class PlatformCanvas; +} + +namespace WebKit { +class WebFont; +} + +namespace ppapi { + +class PPAPI_SHARED_EXPORT PPB_BrowserFont_Trusted_Shared + : public Resource, + public thunk::PPB_BrowserFont_Trusted_API { + public: + // Validates the parameters in thee description. Can be called on any thread. + static bool IsPPFontDescriptionValid( + const PP_BrowserFont_Trusted_Description& desc); + + virtual ~PPB_BrowserFont_Trusted_Shared(); + + static PP_Resource Create( + ResourceObjectType type, + PP_Instance instance, + const PP_BrowserFont_Trusted_Description& description, + const ::ppapi::Preferences& prefs); + + // Resource. + virtual ::ppapi::thunk::PPB_BrowserFont_Trusted_API* + AsPPB_BrowserFont_Trusted_API() OVERRIDE; + + // PPB_Font implementation. + virtual PP_Bool Describe(PP_BrowserFont_Trusted_Description* description, + PP_BrowserFont_Trusted_Metrics* metrics) OVERRIDE; + virtual PP_Bool DrawTextAt(PP_Resource image_data, + const PP_BrowserFont_Trusted_TextRun* text, + const PP_Point* position, + uint32_t color, + const PP_Rect* clip, + PP_Bool image_data_is_opaque) OVERRIDE; + virtual int32_t MeasureText( + const PP_BrowserFont_Trusted_TextRun* text) OVERRIDE; + virtual uint32_t CharacterOffsetForPixel( + const PP_BrowserFont_Trusted_TextRun* text, + int32_t pixel_position) OVERRIDE; + virtual int32_t PixelOffsetForCharacter( + const PP_BrowserFont_Trusted_TextRun* text, + uint32_t char_offset) OVERRIDE; + + private: + PPB_BrowserFont_Trusted_Shared(ResourceObjectType type, + PP_Instance instance, + const PP_BrowserFont_Trusted_Description& desc, + const Preferences& prefs); + + // Internal version of DrawTextAt that takes a mapped PlatformCanvas. + void DrawTextToCanvas(skia::PlatformCanvas* destination, + const PP_BrowserFont_Trusted_TextRun& text, + const PP_Point* position, + uint32_t color, + const PP_Rect* clip, + PP_Bool image_data_is_opaque); + + scoped_ptr<WebKit::WebFont> font_; + + DISALLOW_COPY_AND_ASSIGN(PPB_BrowserFont_Trusted_Shared); +}; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_PRIVATE_PPB_BROWSER_FONT_TRUSTED_SHARED_H_ diff --git a/ppapi/shared_impl/resource.h b/ppapi/shared_impl/resource.h index b0876a2..8f4dc25 100644 --- a/ppapi/shared_impl/resource.h +++ b/ppapi/shared_impl/resource.h @@ -25,6 +25,7 @@ F(PPB_AudioInputTrusted_API) \ F(PPB_AudioTrusted_API) \ F(PPB_Broker_API) \ + F(PPB_BrowserFont_Trusted_API) \ F(PPB_Buffer_API) \ F(PPB_BufferTrusted_API) \ F(PPB_DeviceRef_API) \ @@ -37,7 +38,6 @@ F(PPB_Flash_Menu_API) \ F(PPB_Flash_MessageLoop_API) \ F(PPB_Flash_NetConnector_API) \ - F(PPB_Font_API) \ F(PPB_Graphics2D_API) \ F(PPB_Graphics3D_API) \ F(PPB_ImageData_API) \ diff --git a/ppapi/shared_impl/webkit_forwarding.cc b/ppapi/shared_impl/webkit_forwarding.cc deleted file mode 100644 index a99d754..0000000 --- a/ppapi/shared_impl/webkit_forwarding.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ppapi/shared_impl/webkit_forwarding.h" - -namespace ppapi { - -WebKitForwarding::Font::DrawTextParams::DrawTextParams( - skia::PlatformCanvas* destination_arg, - const TextRun& text_arg, - const PP_Point* position_arg, - uint32_t color_arg, - const PP_Rect* clip_arg, - PP_Bool image_data_is_opaque_arg) - : destination(destination_arg), - text(text_arg), - position(position_arg), - color(color_arg), - clip(clip_arg), - image_data_is_opaque(image_data_is_opaque_arg) { -} - -WebKitForwarding::Font::DrawTextParams::~DrawTextParams() { -} - -WebKitForwarding::Font::~Font() { -} - -WebKitForwarding::~WebKitForwarding() { -} - -} // namespace ppapi - diff --git a/ppapi/shared_impl/webkit_forwarding.h b/ppapi/shared_impl/webkit_forwarding.h deleted file mode 100644 index 2bef621..0000000 --- a/ppapi/shared_impl/webkit_forwarding.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef PPAPI_SHARED_IMPL_WEBKIT_FORWARDING_H_ -#define PPAPI_SHARED_IMPL_WEBKIT_FORWARDING_H_ - -#include <string> - -#include "ppapi/c/pp_bool.h" -#include "ppapi/c/pp_stdint.h" -#include "ppapi/shared_impl/ppapi_shared_export.h" - -struct PP_FontDescription_Dev; -struct PP_FontMetrics_Dev; -struct PP_Point; -struct PP_Rect; - -namespace skia { -class PlatformCanvas; -} - -namespace ppapi { - -struct Preferences; - -class PPAPI_SHARED_EXPORT WebKitForwarding { - public: - class PPAPI_SHARED_EXPORT Font { - public: - // C++ version of PP_TextRun_Dev. Since the functions below will be called - // on an alternate thread in the proxy, and since there are different - // methods of converting PP_Var -> strings in the plugin and the proxy, we - // can't use PP_Vars in the Do* functions below. - struct TextRun { - std::string text; - bool rtl; - bool override_direction; - }; - - // DoDrawText takes too many arguments to be used with base::Bind, so we - // use this struct to hold them. - struct PPAPI_SHARED_EXPORT DrawTextParams { - DrawTextParams(skia::PlatformCanvas* destination_arg, - const TextRun& text_arg, - const PP_Point* position_arg, - uint32_t color_arg, - const PP_Rect* clip_arg, - PP_Bool image_data_is_opaque_arg); - ~DrawTextParams(); - - skia::PlatformCanvas* destination; - const TextRun& text; - const PP_Point* position; - uint32_t color; - const PP_Rect* clip; - PP_Bool image_data_is_opaque; - }; - - virtual ~Font(); - - // The face name in the description is not filled in to avoid a dependency - // on creating vars. Instead, the face name is placed into the given - // string. See class description for waitable_event documentation. If - // non-null, the given event will be set on completion. - virtual void Describe(PP_FontDescription_Dev* description, - std::string* face, - PP_FontMetrics_Dev* metrics, - PP_Bool* result) = 0; - virtual void DrawTextAt(const DrawTextParams& params) = 0; - virtual void MeasureText(const TextRun& text, - int32_t* result) = 0; - virtual void CharacterOffsetForPixel(const TextRun& text, - int32_t pixel_position, - uint32_t* result) = 0; - virtual void PixelOffsetForCharacter(const TextRun& text, - uint32_t char_offset, - int32_t* result) = 0; - }; - - virtual ~WebKitForwarding(); -}; - -} // namespace ppapi - -#endif // PPAPI_SHARED_IMPL_WEBKIT_FORWARDING_H_ diff --git a/ppapi/tests/test_browser_font.cc b/ppapi/tests/test_browser_font.cc new file mode 100644 index 0000000..9f3a2e0 --- /dev/null +++ b/ppapi/tests/test_browser_font.cc @@ -0,0 +1,101 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/tests/test_browser_font.h" + +#include <stdio.h>// ERASEME + +#include "ppapi/tests/test_utils.h" +#include "ppapi/tests/testing_instance.h" +#include "ppapi/cpp/image_data.h" +#include "ppapi/cpp/trusted/browser_font_trusted.h" + +REGISTER_TEST_CASE(BrowserFont); + +bool TestBrowserFont::Init() { + return true; +} + +void TestBrowserFont::RunTests(const std::string& filter) { + RUN_TEST(FontFamilies, filter); + RUN_TEST(Measure, filter); + RUN_TEST(CharPos, filter); + RUN_TEST(Draw, filter); +} + +// Just tests that GetFontFamilies is hooked up & returns something. +std::string TestBrowserFont::TestFontFamilies() { + // This function is only supported out-of-process. + const PPB_Testing_Dev* testing_interface = GetTestingInterface(); + if (testing_interface && !testing_interface->IsOutOfProcess()) + PASS(); + + pp::Var families = pp::BrowserFont_Trusted::GetFontFamilies(instance_); + + ASSERT_TRUE(families.is_string()); + ASSERT_TRUE(!families.AsString().empty()); + PASS(); +} + +// Tests that measuring text behaves reasonably. We aren't sure if the browser +// will be doing kerning or something for the particular default font, so we +// just make a string that we're pretty sure should be more than twice as long +// as another one, and verify that condition. +std::string TestBrowserFont::TestMeasure() { + pp::BrowserFontDescription desc; + pp::BrowserFont_Trusted font(instance_, desc); + + int32_t length1 = font.MeasureText(pp::BrowserFontTextRun("WWW")); + ASSERT_TRUE(length1 > 0); + int32_t length2 = font.MeasureText(pp::BrowserFontTextRun("WWWWWWWW")); + + ASSERT_TRUE(length2 >= length1 * 2); + PASS(); +} + +// Tests that the character/pixel offset functions correctly round-trip. +std::string TestBrowserFont::TestCharPos() { + pp::BrowserFontDescription desc; + pp::BrowserFont_Trusted font(instance_, desc); + + pp::BrowserFontTextRun run("Hello, world"); + uint32_t original_char = 3; + uint32_t pixel_offset = font.PixelOffsetForCharacter(run, original_char); + ASSERT_TRUE(pixel_offset > 0); + + uint32_t computed_char = font.CharacterOffsetForPixel( + run, static_cast<int32_t>(pixel_offset)); + ASSERT_TRUE(computed_char == original_char); + + PASS(); +} + +// Tests that drawing some text produces "some" output. +std::string TestBrowserFont::TestDraw() { + pp::BrowserFontDescription desc; + desc.set_size(100); + pp::BrowserFont_Trusted font(instance_, desc); + + const int kSize = 256; + pp::ImageData image(instance_, pp::ImageData::GetNativeImageDataFormat(), + pp::Size(kSize, kSize), true); + ASSERT_TRUE(!image.is_null()); + + const uint32_t kColor = 0xFFFFFFFF; + font.DrawSimpleText(&image, "Hello", pp::Point(0, 0), kColor, false); + + // Expect that some pixel is nonzero. Due to blending, there may be rounding + // errors and checking for exact white may not be correct. + bool found = false; + for (int y = 0; y < kSize; y++) { + for (int x = 0; x < kSize; x++) { + if (*image.GetAddr32(pp::Point(x, y)) != 0) { + found = true; + break; + } + } + } + ASSERT_TRUE(found); + PASS(); +} diff --git a/ppapi/tests/test_browser_font.h b/ppapi/tests/test_browser_font.h new file mode 100644 index 0000000..eba1c7e --- /dev/null +++ b/ppapi/tests/test_browser_font.h @@ -0,0 +1,25 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_TESTS_TEST_BROWSER_FONT_H_ +#define PPAPI_TESTS_TEST_BROWSER_FONT_H_ + +#include "ppapi/tests/test_case.h" + +class TestBrowserFont : public TestCase { + public: + TestBrowserFont(TestingInstance* instance) : TestCase(instance) {} + + // TestCase implementation. + virtual bool Init(); + virtual void RunTests(const std::string& filter); + + private: + std::string TestFontFamilies(); + std::string TestMeasure(); + std::string TestCharPos(); + std::string TestDraw(); +}; + +#endif // PPAPI_TESTS_TEST_BROWSER_FONT_H_ diff --git a/ppapi/thunk/interfaces_ppb_private.h b/ppapi/thunk/interfaces_ppb_private.h index db888b1..12cc2fd 100644 --- a/ppapi/thunk/interfaces_ppb_private.h +++ b/ppapi/thunk/interfaces_ppb_private.h @@ -13,6 +13,8 @@ PROXIED_API(PPB_UDPSocket_Private) PROXIED_IFACE(PPB_Broker, PPB_BROKER_TRUSTED_INTERFACE_0_2, PPB_BrokerTrusted_0_2) +PROXIED_IFACE(PPB_Instance, PPB_BROWSERFONT_TRUSTED_INTERFACE_1_0, + PPB_BrowserFont_Trusted_1_0) PROXIED_IFACE(PPB_Instance, PPB_CHARSET_TRUSTED_INTERFACE_1_0, PPB_CharSet_Trusted_1_0) PROXIED_IFACE(PPB_FileRef, PPB_FILEREFPRIVATE_INTERFACE_0_1, @@ -31,4 +33,10 @@ PROXIED_IFACE(PPB_TCPSocket_Private, PPB_TCPSOCKET_PRIVATE_INTERFACE_0_3, PROXIED_IFACE(PPB_UDPSocket_Private, PPB_UDPSOCKET_PRIVATE_INTERFACE_0_2, PPB_UDPSocket_Private_0_2) +// Hack to keep font working. The Font 0.6 API is binary compatible with +// BrowserFont 1.0, so just map the string to the same thing. +// TODO(brettw) remove support for the old Font API. +PROXIED_IFACE(PPB_Instance, PPB_FONT_DEV_INTERFACE_0_6, + PPB_BrowserFont_Trusted_1_0) + #include "ppapi/thunk/interfaces_postamble.h" diff --git a/ppapi/thunk/interfaces_ppb_public_dev.h b/ppapi/thunk/interfaces_ppb_public_dev.h index cd48609..b4872aa 100644 --- a/ppapi/thunk/interfaces_ppb_public_dev.h +++ b/ppapi/thunk/interfaces_ppb_public_dev.h @@ -12,7 +12,6 @@ PROXIED_API(PPB_Buffer) PROXIED_API(PPB_CursorControl) UNPROXIED_API(PPB_DirectoryReader) PROXIED_API(PPB_FileChooser) -PROXIED_API(PPB_Font) PROXIED_API(PPB_Graphics3D) UNPROXIED_API(PPB_LayerCompositor) UNPROXIED_API(PPB_Scrollbar) @@ -40,7 +39,6 @@ UNPROXIED_IFACE(PPB_DirectoryReader, PPB_DIRECTORYREADER_DEV_INTERFACE_0_5, UNPROXIED_IFACE(PPB_Find, PPB_FIND_DEV_INTERFACE_0_3, PPB_Find_Dev_0_3) PROXIED_IFACE(PPB_FileChooser, PPB_FILECHOOSER_DEV_INTERFACE_0_5, PPB_FileChooser_Dev_0_5) -PROXIED_IFACE(PPB_Font, PPB_FONT_DEV_INTERFACE_0_6, PPB_Font_Dev_0_6) PROXIED_IFACE(PPB_Instance, PPB_CHAR_SET_DEV_INTERFACE_0_4, PPB_CharSet_Dev_0_4) PROXIED_IFACE(PPB_Instance, PPB_CONSOLE_DEV_INTERFACE_0_1, PPB_Console_Dev_0_1) PROXIED_IFACE(PPB_Instance, PPB_GAMEPAD_DEV_INTERFACE_0_1, PPB_Gamepad_Dev_0_1) diff --git a/ppapi/thunk/ppb_browser_font_trusted_api.h b/ppapi/thunk/ppb_browser_font_trusted_api.h new file mode 100644 index 0000000..85c188a --- /dev/null +++ b/ppapi/thunk/ppb_browser_font_trusted_api.h @@ -0,0 +1,39 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_THUNK_PPB_BROWSER_FONT_TRUSTED_API_H_ +#define PPAPI_THUNK_PPB_BROWSER_FONT_TRUSTED_API_H_ + +#include "ppapi/c/trusted/ppb_browser_font_trusted.h" +#include "ppapi/thunk/ppapi_thunk_export.h" + +namespace ppapi { +namespace thunk { + +// API for font resources. +class PPAPI_THUNK_EXPORT PPB_BrowserFont_Trusted_API { + public: + virtual ~PPB_BrowserFont_Trusted_API() {} + + virtual PP_Bool Describe(PP_BrowserFont_Trusted_Description* description, + PP_BrowserFont_Trusted_Metrics* metrics) = 0; + virtual PP_Bool DrawTextAt(PP_Resource image_data, + const PP_BrowserFont_Trusted_TextRun* text, + const PP_Point* position, + uint32_t color, + const PP_Rect* clip, + PP_Bool image_data_is_opaque) = 0; + virtual int32_t MeasureText(const PP_BrowserFont_Trusted_TextRun* text) = 0; + virtual uint32_t CharacterOffsetForPixel( + const PP_BrowserFont_Trusted_TextRun* text, + int32_t pixel_position) = 0; + virtual int32_t PixelOffsetForCharacter( + const PP_BrowserFont_Trusted_TextRun* text, + uint32_t char_offset) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_BROWSER_FONT_TRUSTED_API_H_ diff --git a/ppapi/thunk/ppb_font_thunk.cc b/ppapi/thunk/ppb_browser_font_trusted_thunk.cc index 23e21cd..bcbc798 100644 --- a/ppapi/thunk/ppb_font_thunk.cc +++ b/ppapi/thunk/ppb_browser_font_trusted_thunk.cc @@ -4,7 +4,7 @@ #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/enter.h" -#include "ppapi/thunk/ppb_font_api.h" +#include "ppapi/thunk/ppb_browser_font_trusted_api.h" #include "ppapi/thunk/resource_creation_api.h" namespace ppapi { @@ -12,30 +12,32 @@ namespace thunk { namespace { +typedef EnterResource<PPB_BrowserFont_Trusted_API> EnterBrowserFont; + PP_Var GetFontFamilies(PP_Instance instance) { - EnterFunction<PPB_Font_FunctionAPI> enter(instance, true); + EnterInstance enter(instance); if (enter.failed()) return PP_MakeUndefined(); return enter.functions()->GetFontFamilies(instance); } PP_Resource Create(PP_Instance instance, - const PP_FontDescription_Dev* description) { - EnterFunction<ResourceCreationAPI> enter(instance, true); + const PP_BrowserFont_Trusted_Description* description) { + EnterResourceCreation enter(instance); if (enter.failed()) return 0; - return enter.functions()->CreateFontObject(instance, description); + return enter.functions()->CreateBrowserFont(instance, description); } -PP_Bool IsFont(PP_Resource resource) { - EnterResource<PPB_Font_API> enter(resource, false); +PP_Bool IsBrowserFont(PP_Resource resource) { + EnterBrowserFont enter(resource, false); return enter.succeeded() ? PP_TRUE : PP_FALSE; } PP_Bool Describe(PP_Resource font_id, - PP_FontDescription_Dev* description, - PP_FontMetrics_Dev* metrics) { - EnterResource<PPB_Font_API> enter(font_id, true); + PP_BrowserFont_Trusted_Description* description, + PP_BrowserFont_Trusted_Metrics* metrics) { + EnterBrowserFont enter(font_id, true); if (enter.failed()) return PP_FALSE; return enter.object()->Describe(description, metrics); @@ -43,47 +45,48 @@ PP_Bool Describe(PP_Resource font_id, PP_Bool DrawTextAt(PP_Resource font_id, PP_Resource image_data, - const PP_TextRun_Dev* text, + const PP_BrowserFont_Trusted_TextRun* text, const PP_Point* position, uint32_t color, const PP_Rect* clip, PP_Bool image_data_is_opaque) { - EnterResource<PPB_Font_API> enter(font_id, true); + EnterBrowserFont enter(font_id, true); if (enter.failed()) return PP_FALSE; return enter.object()->DrawTextAt(image_data, text, position, color, clip, image_data_is_opaque); } -int32_t MeasureText(PP_Resource font_id, const PP_TextRun_Dev* text) { - EnterResource<PPB_Font_API> enter(font_id, true); +int32_t MeasureText(PP_Resource font_id, + const PP_BrowserFont_Trusted_TextRun* text) { + EnterBrowserFont enter(font_id, true); if (enter.failed()) return -1; return enter.object()->MeasureText(text); } uint32_t CharacterOffsetForPixel(PP_Resource font_id, - const PP_TextRun_Dev* text, + const PP_BrowserFont_Trusted_TextRun* text, int32_t pixel_position) { - EnterResource<PPB_Font_API> enter(font_id, true); + EnterBrowserFont enter(font_id, true); if (enter.failed()) return -1; return enter.object()->CharacterOffsetForPixel(text, pixel_position); } int32_t PixelOffsetForCharacter(PP_Resource font_id, - const PP_TextRun_Dev* text, + const PP_BrowserFont_Trusted_TextRun* text, uint32_t char_offset) { - EnterResource<PPB_Font_API> enter(font_id, true); + EnterBrowserFont enter(font_id, true); if (enter.failed()) return -1; return enter.object()->PixelOffsetForCharacter(text, char_offset); } -const PPB_Font_Dev g_ppb_font_thunk = { +const PPB_BrowserFont_Trusted_1_0 g_ppb_browser_font_trusted_thunk = { &GetFontFamilies, &Create, - &IsFont, + &IsBrowserFont, &Describe, &DrawTextAt, &MeasureText, @@ -93,8 +96,8 @@ const PPB_Font_Dev g_ppb_font_thunk = { } // namespace -const PPB_Font_Dev_0_6* GetPPB_Font_Dev_0_6_Thunk() { - return &g_ppb_font_thunk; +const PPB_BrowserFont_Trusted_1_0* GetPPB_BrowserFont_Trusted_1_0_Thunk() { + return &g_ppb_browser_font_trusted_thunk; } } // namespace thunk diff --git a/ppapi/thunk/ppb_font_api.h b/ppapi/thunk/ppb_font_api.h deleted file mode 100644 index e85bb1b..0000000 --- a/ppapi/thunk/ppb_font_api.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef PPAPI_THUNK_PPB_FONT_API_H_ -#define PPAPI_THUNK_PPB_FONT_API_H_ - -#include "ppapi/c/dev/ppb_font_dev.h" -#include "ppapi/shared_impl/api_id.h" -#include "ppapi/thunk/ppapi_thunk_export.h" - -namespace ppapi { -namespace thunk { - -// API for static font functions. -class PPB_Font_FunctionAPI { - public: - virtual ~PPB_Font_FunctionAPI() {} - - virtual PP_Var GetFontFamilies(PP_Instance instance) = 0; - - static const ApiID kApiID = API_ID_PPB_FONT; -}; - -// API for font resources. -class PPAPI_THUNK_EXPORT PPB_Font_API { - public: - virtual ~PPB_Font_API() {} - - virtual PP_Bool Describe(PP_FontDescription_Dev* description, - PP_FontMetrics_Dev* metrics) = 0; - virtual PP_Bool DrawTextAt(PP_Resource image_data, - const PP_TextRun_Dev* text, - const PP_Point* position, - uint32_t color, - const PP_Rect* clip, - PP_Bool image_data_is_opaque) = 0; - virtual int32_t MeasureText(const PP_TextRun_Dev* text) = 0; - virtual uint32_t CharacterOffsetForPixel(const PP_TextRun_Dev* text, - int32_t pixel_position) = 0; - virtual int32_t PixelOffsetForCharacter(const PP_TextRun_Dev* text, - uint32_t char_offset) = 0; -}; - -} // namespace thunk -} // namespace ppapi - -#endif // PPAPI_THUNK_PPB_FONT_API_H_ diff --git a/ppapi/thunk/ppb_instance_api.h b/ppapi/thunk/ppb_instance_api.h index 6d0339a..741f762 100644 --- a/ppapi/thunk/ppb_instance_api.h +++ b/ppapi/thunk/ppb_instance_api.h @@ -62,6 +62,9 @@ class PPB_Instance_FunctionAPI { virtual void SelectedFindResultChanged(PP_Instance instance, int32_t index) = 0; + // Font. + virtual PP_Var GetFontFamilies(PP_Instance instance) = 0; + // Fullscreen. virtual PP_Bool SetFullscreen(PP_Instance instance, PP_Bool fullscreen) = 0; diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index ccfe7a59..05c90c2 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -23,7 +23,7 @@ #include "ppapi/shared_impl/api_id.h" struct PP_Flash_Menu; -struct PP_FontDescription_Dev; +struct PP_BrowserFont_Trusted_Description; struct PP_Size; namespace ppapi { @@ -56,6 +56,9 @@ class ResourceCreationAPI { void* user_data) = 0; virtual PP_Resource CreateAudioInputTrusted(PP_Instance instance) = 0; virtual PP_Resource CreateBroker(PP_Instance instance) = 0; + virtual PP_Resource CreateBrowserFont( + PP_Instance instance, + const PP_BrowserFont_Trusted_Description* description) = 0; virtual PP_Resource CreateBuffer(PP_Instance instance, uint32_t size) = 0; virtual PP_Resource CreateDirectoryReader(PP_Resource directory_ref) = 0; virtual PP_Resource CreateFileChooser( @@ -71,10 +74,6 @@ class ResourceCreationAPI { const PP_Flash_Menu* menu_data) = 0; virtual PP_Resource CreateFlashMessageLoop(PP_Instance instance) = 0; virtual PP_Resource CreateFlashNetConnector(PP_Instance instance) = 0; - // Note: can't be called CreateFont due to Windows #defines. - virtual PP_Resource CreateFontObject( - PP_Instance instance, - const PP_FontDescription_Dev* description) = 0; virtual PP_Resource CreateGraphics2D(PP_Instance instance, const PP_Size& size, PP_Bool is_always_opaque) = 0; diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index bd66b1b..36cbcde 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -285,8 +285,6 @@ '../plugins/ppapi/ppb_flash_message_loop_impl.h', '../plugins/ppapi/ppb_flash_net_connector_impl.cc', '../plugins/ppapi/ppb_flash_net_connector_impl.h', - '../plugins/ppapi/ppb_font_impl.cc', - '../plugins/ppapi/ppb_font_impl.h', '../plugins/ppapi/ppb_gpu_blacklist_private_impl.cc', '../plugins/ppapi/ppb_gpu_blacklist_private_impl.h', '../plugins/ppapi/ppb_graphics_2d_impl.cc', diff --git a/webkit/plugins/ppapi/host_globals.cc b/webkit/plugins/ppapi/host_globals.cc index a8cc9e3..a3e5f31 100644 --- a/webkit/plugins/ppapi/host_globals.cc +++ b/webkit/plugins/ppapi/host_globals.cc @@ -22,7 +22,6 @@ #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_cursor_control_impl.h" #include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h" -#include "webkit/plugins/ppapi/ppb_font_impl.h" #include "webkit/plugins/ppapi/ppb_text_input_impl.h" #include "webkit/plugins/ppapi/resource_creation_impl.h" @@ -145,9 +144,6 @@ HostGlobals::~HostGlobals() { case ::ppapi::API_ID_PPB_CURSORCONTROL: proxy.reset(new PPB_CursorControl_Impl(instance)); break; - case ::ppapi::API_ID_PPB_FONT: - proxy.reset(new PPB_Font_FunctionImpl(instance)); - break; case ::ppapi::API_ID_PPB_TEXT_INPUT: proxy.reset(new PPB_TextInput_Impl(instance)); break; diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 5a7a4e9..5622c7f 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -82,6 +82,7 @@ #include "ppapi/c/trusted/ppb_audio_input_trusted_dev.h" #include "ppapi/c/trusted/ppb_audio_trusted.h" #include "ppapi/c/trusted/ppb_broker_trusted.h" +#include "ppapi/c/trusted/ppb_browser_font_trusted.h" #include "ppapi/c/trusted/ppb_buffer_trusted.h" #include "ppapi/c/trusted/ppb_char_set_trusted.h" #include "ppapi/c/trusted/ppb_file_chooser_trusted.h" @@ -107,7 +108,6 @@ #include "webkit/plugins/ppapi/ppb_flash_impl.h" #include "webkit/plugins/ppapi/ppb_flash_menu_impl.h" #include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h" -#include "webkit/plugins/ppapi/ppb_font_impl.h" #include "webkit/plugins/ppapi/ppb_gpu_blacklist_private_impl.h" #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" #include "webkit/plugins/ppapi/ppb_image_data_impl.h" diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index a1f541a..5d061b9 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -1857,6 +1857,11 @@ PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) { return StringVar::StringToPPVar(encoding); } +PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) { + // No in-process implementation. + return PP_MakeUndefined(); +} + void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, int32_t total, PP_Bool final_result) { diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index 0156cda..c9179b2 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -331,6 +331,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : PP_Var script, PP_Var* exception) OVERRIDE; virtual PP_Var GetDefaultCharSet(PP_Instance instance) OVERRIDE; + virtual PP_Var GetFontFamilies(PP_Instance instance) OVERRIDE; virtual void NumberOfFindResultsChanged(PP_Instance instance, int32_t total, PP_Bool final_result) OVERRIDE; diff --git a/webkit/plugins/ppapi/ppb_font_impl.cc b/webkit/plugins/ppapi/ppb_font_impl.cc deleted file mode 100644 index c18106a..0000000 --- a/webkit/plugins/ppapi/ppb_font_impl.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/plugins/ppapi/ppb_font_impl.h" - -#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" - -namespace webkit { - -namespace ppapi { - -PPB_Font_FunctionImpl::PPB_Font_FunctionImpl(PluginInstance* instance) - : instance_(instance) { -} - -PPB_Font_FunctionImpl::~PPB_Font_FunctionImpl() { -} - -::ppapi::thunk::PPB_Font_FunctionAPI* -PPB_Font_FunctionImpl::AsFont_FunctionAPI() { - return this; -} - -// TODO(ananta) -// We need to wire this up to the proxy. -PP_Var PPB_Font_FunctionImpl::GetFontFamilies(PP_Instance instance) { - return PP_MakeUndefined(); -} - -} // namespace ppapi - -} // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_font_impl.h b/webkit/plugins/ppapi/ppb_font_impl.h deleted file mode 100644 index c21b18e..0000000 --- a/webkit/plugins/ppapi/ppb_font_impl.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_PLUGINS_PPAPI_PPB_FONT_IMPL_H_ -#define WEBKIT_PLUGINS_PPAPI_PPB_FONT_IMPL_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ppapi/c/pp_instance.h" -#include "ppapi/shared_impl/function_group_base.h" -#include "ppapi/thunk/ppb_font_api.h" - -namespace webkit { -namespace ppapi { - -class PluginInstance; - -class PPB_Font_FunctionImpl : public ::ppapi::FunctionGroupBase, - public ::ppapi::thunk::PPB_Font_FunctionAPI { - public: - explicit PPB_Font_FunctionImpl(PluginInstance* instance); - virtual ~PPB_Font_FunctionImpl(); - - // FunctionGroupBase overrides. - virtual ::ppapi::thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI(); - - // PPB_Font_FunctionAPI implementation. - virtual PP_Var GetFontFamilies(PP_Instance instance) OVERRIDE; - - private: - PluginInstance* instance_; - - DISALLOW_COPY_AND_ASSIGN(PPB_Font_FunctionImpl); -}; - -} // namespace ppapi - -} // namespace webkit. - -#endif // WEBKIT_PLUGINS_PPAPI_PPB_FONT_IMPL_H_ diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index e0ca2fe..120c587 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -6,7 +6,7 @@ #include "ppapi/c/pp_size.h" #include "ppapi/shared_impl/ppb_audio_config_shared.h" -#include "ppapi/shared_impl/private/ppb_font_shared.h" +#include "ppapi/shared_impl/private/ppb_browser_font_trusted_shared.h" #include "ppapi/shared_impl/ppb_input_event_shared.h" #include "ppapi/shared_impl/ppb_resource_array_shared.h" #include "ppapi/shared_impl/var.h" @@ -97,6 +97,18 @@ PP_Resource ResourceCreationImpl::CreateBroker(PP_Instance instance) { return (new PPB_Broker_Impl(instance))->GetReference(); } +PP_Resource ResourceCreationImpl::CreateBrowserFont( + PP_Instance instance, + const PP_BrowserFont_Trusted_Description* description) { + PluginInstance* plugin_instance = + ResourceHelper::PPInstanceToPluginInstance(instance); + if (!plugin_instance) + return 0; + return ::ppapi::PPB_BrowserFont_Trusted_Shared::Create( + ::ppapi::OBJECT_IS_IMPL, instance, *description, + plugin_instance->delegate()->GetPreferences()); +} + PP_Resource ResourceCreationImpl::CreateBuffer(PP_Instance instance, uint32_t size) { return PPB_Buffer_Impl::Create(instance, size); @@ -145,18 +157,6 @@ PP_Resource ResourceCreationImpl::CreateFlashNetConnector( return (new PPB_Flash_NetConnector_Impl(instance))->GetReference(); } -PP_Resource ResourceCreationImpl::CreateFontObject( - PP_Instance instance, - const PP_FontDescription_Dev* description) { - PluginInstance* plugin_instance = - ResourceHelper::PPInstanceToPluginInstance(instance); - if (!plugin_instance) - return 0; - return ::ppapi::PPB_Font_Shared::Create( - ::ppapi::OBJECT_IS_IMPL, instance, *description, - plugin_instance->delegate()->GetPreferences()); -} - PP_Resource ResourceCreationImpl::CreateGraphics2D( PP_Instance instance, const PP_Size& size, diff --git a/webkit/plugins/ppapi/resource_creation_impl.h b/webkit/plugins/ppapi/resource_creation_impl.h index 9b48ccb..d4595ae 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.h +++ b/webkit/plugins/ppapi/resource_creation_impl.h @@ -40,6 +40,9 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase, void* user_data) OVERRIDE; virtual PP_Resource CreateAudioInputTrusted(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateBroker(PP_Instance instance) OVERRIDE; + virtual PP_Resource CreateBrowserFont( + PP_Instance instance, + const PP_BrowserFont_Trusted_Description* description) OVERRIDE; virtual PP_Resource CreateBuffer(PP_Instance instance, uint32_t size) OVERRIDE; virtual PP_Resource CreateDirectoryReader(PP_Resource directory_ref) OVERRIDE; @@ -56,9 +59,6 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase, const PP_Flash_Menu* menu_data) OVERRIDE; virtual PP_Resource CreateFlashMessageLoop(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateFlashNetConnector(PP_Instance instance) OVERRIDE; - virtual PP_Resource CreateFontObject( - PP_Instance instance, - const PP_FontDescription_Dev* description) OVERRIDE; virtual PP_Resource CreateGraphics2D(PP_Instance pp_instance, const PP_Size& size, PP_Bool is_always_opaque) OVERRIDE; |