summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-26 19:05:28 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-26 19:05:28 +0000
commit208aad79d76c5c9a5e05322be674b2d81738cb68 (patch)
tree6286cbea3bd340d8d5f61af9f6ace0b3d15e236c /ppapi
parentb6b19e26bb00c8e8bc4ab91b535520352fb009f9 (diff)
downloadchromium_src-208aad79d76c5c9a5e05322be674b2d81738cb68.zip
chromium_src-208aad79d76c5c9a5e05322be674b2d81738cb68.tar.gz
chromium_src-208aad79d76c5c9a5e05322be674b2d81738cb68.tar.bz2
Use the WebKit default fonts when specifying generic font families.
This pipes through a new preferences object that the font system can use. It now picks up these faces as well as the default font size. Clarify this behavior in the interface. TEST=manual (font example included). BUG=none Review URL: http://codereview.chromium.org/7053022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86870 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/c/dev/ppb_font_dev.h19
-rw-r--r--ppapi/examples/font/simple_font.cc59
-rw-r--r--ppapi/ppapi_shared.gypi2
-rw-r--r--ppapi/proxy/host_dispatcher.cc4
-rw-r--r--ppapi/proxy/host_dispatcher.h7
-rw-r--r--ppapi/proxy/plugin_dispatcher.cc18
-rw-r--r--ppapi/proxy/plugin_dispatcher.h14
-rw-r--r--ppapi/proxy/ppapi_messages.h14
-rw-r--r--ppapi/proxy/ppb_font_proxy.cc5
-rw-r--r--ppapi/shared_impl/ppapi_preferences.cc28
-rw-r--r--ppapi/shared_impl/ppapi_preferences.h30
-rw-r--r--ppapi/shared_impl/webkit_forwarding.h4
12 files changed, 192 insertions, 12 deletions
diff --git a/ppapi/c/dev/ppb_font_dev.h b/ppapi/c/dev/ppb_font_dev.h
index 48b990c..fd2652e 100644
--- a/ppapi/c/dev/ppb_font_dev.h
+++ b/ppapi/c/dev/ppb_font_dev.h
@@ -56,18 +56,31 @@ PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_FontWeight_Dev, 4);
struct PP_FontDescription_Dev {
/**
* Font face name as a string. This can also be an undefined var, in which
- * case the generic family will be obeyed.
+ * 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 face is an undefined var, this specifies the generic font family type
- * to use. If the face is specified, this will be ignored.
+ * 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_FontFamily_Dev 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;
diff --git a/ppapi/examples/font/simple_font.cc b/ppapi/examples/font/simple_font.cc
index c1bfdef..a5f8914 100644
--- a/ppapi/examples/font/simple_font.cc
+++ b/ppapi/examples/font/simple_font.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <stdio.h>
+
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/dev/font_dev.h"
#include "ppapi/cpp/graphics_2d.h"
@@ -31,22 +33,71 @@ class MyInstance : public pp::Instance {
pp::FontDescription_Dev desc;
desc.set_family(PP_FONTFAMILY_SANSSERIF);
- desc.set_size(30);
+ desc.set_size(100);
pp::Font_Dev 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::Point(10, 40), 0xFF008000, clip, false);
- font.DrawTextAt(&image, pp::TextRun_Dev("Hello"),
- pp::Point(10, 80), 0xFF000080, text_clip, false);
+ 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);
+ 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);
+ 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);
+ 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);
+ monospace_font.DrawSimpleText(
+ &image, DescribeFont(monospace_font, "Monospace font"),
+ pp::Point(10, y), 0xFF000000);
+ y += 20;
+ }
device.PaintImageData(image, pp::Point(0, 0));
device.Flush(pp::CompletionCallback(&DummyCompletionCallback, NULL));
}
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;
+ font.Describe(&desc, &metrics);
+
+ char buf[256];
+ sprintf(buf, "%s = %s %dpt",
+ title, desc.face().AsString().c_str(), desc.size());
+ return std::string(buf);
+ }
+
pp::Size last_size_;
};
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi
index 386159b..4568b56 100644
--- a/ppapi/ppapi_shared.gypi
+++ b/ppapi/ppapi_shared.gypi
@@ -35,6 +35,8 @@
'shared_impl/font_impl.h',
'shared_impl/image_data_impl.cc',
'shared_impl/image_data_impl.h',
+ 'shared_impl/ppapi_preferences.cc',
+ 'shared_impl/ppapi_preferences.h',
'shared_impl/tracker_base.cc',
'shared_impl/tracker_base.h',
'shared_impl/url_util_impl.cc',
diff --git a/ppapi/proxy/host_dispatcher.cc b/ppapi/proxy/host_dispatcher.cc
index 4658fdb..c00390b 100644
--- a/ppapi/proxy/host_dispatcher.cc
+++ b/ppapi/proxy/host_dispatcher.cc
@@ -92,9 +92,11 @@ HostDispatcher::~HostDispatcher() {
bool HostDispatcher::InitHostWithChannel(
Delegate* delegate,
const IPC::ChannelHandle& channel_handle,
- bool is_client) {
+ bool is_client,
+ const ppapi::Preferences& preferences) {
if (!Dispatcher::InitWithChannel(delegate, channel_handle, is_client))
return false;
+ Send(new PpapiMsg_SetPreferences(preferences));
return true;
}
diff --git a/ppapi/proxy/host_dispatcher.h b/ppapi/proxy/host_dispatcher.h
index 608223d..55ba56b 100644
--- a/ppapi/proxy/host_dispatcher.h
+++ b/ppapi/proxy/host_dispatcher.h
@@ -27,6 +27,10 @@ namespace IPC {
class SyncChannel;
}
+namespace ppapi {
+struct Preferences;
+}
+
namespace pp {
namespace proxy {
@@ -48,7 +52,8 @@ class HostDispatcher : public Dispatcher {
// transferred.
virtual bool InitHostWithChannel(Delegate* delegate,
const IPC::ChannelHandle& channel_handle,
- bool is_client);
+ bool is_client,
+ const ppapi::Preferences& preferences);
// The host side maintains a mapping from PP_Instance to Dispatcher so
// that we can send the messages to the right channel.
diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc
index dee2610..4ce47c6 100644
--- a/ppapi/proxy/plugin_dispatcher.cc
+++ b/ppapi/proxy/plugin_dispatcher.cc
@@ -40,7 +40,8 @@ InstanceToDispatcherMap* g_instance_to_dispatcher = NULL;
PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle,
GetInterfaceFunc get_interface)
: Dispatcher(remote_process_handle, get_interface),
- plugin_delegate_(NULL) {
+ plugin_delegate_(NULL),
+ received_preferences_(false) {
SetSerializationRules(new PluginVarSerializationRules);
// As a plugin, we always support the PPP_Class interface. There's no
@@ -122,6 +123,7 @@ bool PluginDispatcher::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg)
IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface)
+ IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnMsgSetPreferences)
IPC_END_MESSAGE_MAP()
return handled;
}
@@ -274,6 +276,20 @@ void PluginDispatcher::OnMsgSupportsInterface(
*result = true;
}
+void PluginDispatcher::OnMsgSetPreferences(const ::ppapi::Preferences& prefs) {
+ // The renderer may send us preferences more than once (currently this
+ // happens every time a new plugin instance is created). Since we don't have
+ // a way to signal to the plugin that the preferences have changed, changing
+ // the default fonts and such in the middle of a running plugin could be
+ // confusing to it. As a result, we never allow the preferences to be changed
+ // once they're set. The user will have to restart to get new font prefs
+ // propogated to plugins.
+ if (!received_preferences_) {
+ received_preferences_ = true;
+ preferences_ = prefs;
+ }
+}
+
} // namespace proxy
} // namespace pp
diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h
index 29460fa..1964d94 100644
--- a/ppapi/proxy/plugin_dispatcher.h
+++ b/ppapi/proxy/plugin_dispatcher.h
@@ -15,6 +15,7 @@
#include "ppapi/c/pp_instance.h"
#include "ppapi/proxy/dispatcher.h"
#include "ppapi/shared_impl/function_group_base.h"
+#include "ppapi/shared_impl/ppapi_preferences.h"
class MessageLoop;
@@ -22,6 +23,10 @@ namespace base {
class WaitableEvent;
}
+namespace ppapi {
+struct Preferences;
+}
+
namespace pp {
namespace proxy {
@@ -108,6 +113,9 @@ class PluginDispatcher : public Dispatcher {
// Returns the WebKitForwarding object used to forward events to WebKit.
ppapi::WebKitForwarding* GetWebKitForwarding();
+ // Returns the Preferences.
+ const ppapi::Preferences& preferences() const { return preferences_; }
+
// Returns the "new-style" function API for the given interface ID, creating
// it if necessary.
// TODO(brettw) this is in progress. It should be merged with the target
@@ -124,6 +132,7 @@ class PluginDispatcher : public Dispatcher {
// IPC message handlers.
void OnMsgSupportsInterface(const std::string& interface_name, bool* result);
+ void OnMsgSetPreferences(const ::ppapi::Preferences& prefs);
PluginDelegate* plugin_delegate_;
@@ -140,6 +149,11 @@ class PluginDispatcher : public Dispatcher {
typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap;
InstanceDataMap instance_map_;
+ // The preferences sent from the host. We only want to set this once, which
+ // is what the received_preferences_ indicates. See OnMsgSetPreferences.
+ bool received_preferences_;
+ ppapi::Preferences preferences_;
+
DISALLOW_COPY_AND_ASSIGN(PluginDispatcher);
};
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index cd65fe8..49f0045 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -29,6 +29,7 @@
#include "ppapi/proxy/ppapi_param_traits.h"
#include "ppapi/proxy/serialized_flash_menu.h"
#include "ppapi/proxy/serialized_structs.h"
+#include "ppapi/shared_impl/ppapi_preferences.h"
#define IPC_MESSAGE_START PpapiMsgStart
@@ -47,6 +48,15 @@ IPC_STRUCT_TRAITS_BEGIN(PP_Rect)
IPC_STRUCT_TRAITS_MEMBER(size)
IPC_STRUCT_TRAITS_END()
+IPC_STRUCT_TRAITS_BEGIN(::ppapi::Preferences)
+ IPC_STRUCT_TRAITS_MEMBER(standard_font_family)
+ IPC_STRUCT_TRAITS_MEMBER(fixed_font_family)
+ IPC_STRUCT_TRAITS_MEMBER(serif_font_family)
+ IPC_STRUCT_TRAITS_MEMBER(sans_serif_font_family)
+ IPC_STRUCT_TRAITS_MEMBER(default_font_size)
+ IPC_STRUCT_TRAITS_MEMBER(default_fixed_font_size)
+IPC_STRUCT_TRAITS_END()
+
// These are from the browser to the plugin.
// Loads the given plugin.
IPC_MESSAGE_CONTROL1(PpapiMsg_LoadPlugin, FilePath /* path */)
@@ -75,6 +85,10 @@ IPC_SYNC_MESSAGE_CONTROL1_1(PpapiMsg_ReserveInstanceId,
PP_Instance /* instance */,
bool /* usable */)
+// Passes the WebKit preferences to the plugin.
+IPC_MESSAGE_CONTROL1(PpapiMsg_SetPreferences,
+ ::ppapi::Preferences)
+
// Sent in both directions to see if the other side supports the given
// interface.
IPC_SYNC_MESSAGE_CONTROL1_1(PpapiMsg_SupportsInterface,
diff --git a/ppapi/proxy/ppb_font_proxy.cc b/ppapi/proxy/ppb_font_proxy.cc
index 53eac45..eab4494 100644
--- a/ppapi/proxy/ppb_font_proxy.cc
+++ b/ppapi/proxy/ppb_font_proxy.cc
@@ -10,6 +10,7 @@
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/ppb_image_data_proxy.h"
#include "ppapi/proxy/serialized_var.h"
+#include "ppapi/shared_impl/ppapi_preferences.h"
#include "ppapi/shared_impl/resource_object_base.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_image_data_api.h"
@@ -104,7 +105,9 @@ Font::Font(const HostResource& resource,
RunOnWebKitThread(base::Bind(&WebKitForwarding::CreateFontForwarding,
base::Unretained(forwarding),
&webkit_event_, desc,
- face ? *face : std::string(), &result));
+ face ? *face : std::string(),
+ GetDispatcher()->preferences(),
+ &result));
font_forwarding_.reset(result);
}
diff --git a/ppapi/shared_impl/ppapi_preferences.cc b/ppapi/shared_impl/ppapi_preferences.cc
new file mode 100644
index 0000000..1448806
--- /dev/null
+++ b/ppapi/shared_impl/ppapi_preferences.cc
@@ -0,0 +1,28 @@
+// 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/ppapi_preferences.h"
+
+#include "webkit/glue/webpreferences.h"
+
+namespace ppapi {
+
+Preferences::Preferences()
+ : default_font_size(0),
+ default_fixed_font_size(0) {
+}
+
+Preferences::Preferences(const WebPreferences& prefs)
+ : standard_font_family(prefs.standard_font_family),
+ fixed_font_family(prefs.fixed_font_family),
+ serif_font_family(prefs.serif_font_family),
+ sans_serif_font_family(prefs.sans_serif_font_family),
+ default_font_size(prefs.default_font_size),
+ default_fixed_font_size(prefs.default_fixed_font_size) {
+}
+
+Preferences::~Preferences() {
+}
+
+} // namespace ppapi
diff --git a/ppapi/shared_impl/ppapi_preferences.h b/ppapi/shared_impl/ppapi_preferences.h
new file mode 100644
index 0000000..e026290
--- /dev/null
+++ b/ppapi/shared_impl/ppapi_preferences.h
@@ -0,0 +1,30 @@
+// 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_PPAPI_PREFERENCES_H_
+#define PPAPI_SHARED_IMPL_PPAPI_PREFERENCES_H_
+
+#include "base/string16.h"
+
+struct WebPreferences;
+
+namespace ppapi {
+
+struct Preferences {
+ public:
+ Preferences();
+ explicit Preferences(const WebPreferences& prefs);
+ ~Preferences();
+
+ string16 standard_font_family;
+ string16 fixed_font_family;
+ string16 serif_font_family;
+ string16 sans_serif_font_family;
+ int default_font_size;
+ int default_fixed_font_size;
+};
+
+} // namespace ppapi
+
+#endif // PPAPI_SHARED_IMPL_PPAPI_PREFERENCES_H_
diff --git a/ppapi/shared_impl/webkit_forwarding.h b/ppapi/shared_impl/webkit_forwarding.h
index 4f45344..2094523 100644
--- a/ppapi/shared_impl/webkit_forwarding.h
+++ b/ppapi/shared_impl/webkit_forwarding.h
@@ -25,6 +25,8 @@ class PlatformCanvas;
namespace ppapi {
+struct Preferences;
+
class WebKitForwarding {
public:
class Font {
@@ -93,8 +95,8 @@ class WebKitForwarding {
virtual void CreateFontForwarding(base::WaitableEvent* event,
const PP_FontDescription_Dev& desc,
const std::string& desc_face,
+ const Preferences& prefs,
Font** result) = 0;
-
};
} // namespace ppapi