OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 | 6 |
7 #include "ppapi/cpp/completion_callback.h" | 7 #include "ppapi/cpp/completion_callback.h" |
8 #include "ppapi/cpp/dev/font_dev.h" | |
9 #include "ppapi/cpp/graphics_2d.h" | 8 #include "ppapi/cpp/graphics_2d.h" |
10 #include "ppapi/cpp/image_data.h" | 9 #include "ppapi/cpp/image_data.h" |
11 #include "ppapi/cpp/instance.h" | 10 #include "ppapi/cpp/instance.h" |
12 #include "ppapi/cpp/module.h" | 11 #include "ppapi/cpp/module.h" |
13 #include "ppapi/cpp/rect.h" | 12 #include "ppapi/cpp/rect.h" |
14 #include "ppapi/cpp/size.h" | 13 #include "ppapi/cpp/size.h" |
| 14 #include "ppapi/cpp/trusted/browser_font_trusted.h" |
15 | 15 |
16 static void DummyCompletionCallback(void* /*user_data*/, int32_t /*result*/) { | 16 static void DummyCompletionCallback(void* /*user_data*/, int32_t /*result*/) { |
17 } | 17 } |
18 | 18 |
19 class MyInstance : public pp::Instance { | 19 class MyInstance : public pp::Instance { |
20 public: | 20 public: |
21 MyInstance(PP_Instance instance) | 21 MyInstance(PP_Instance instance) |
22 : pp::Instance(instance) { | 22 : pp::Instance(instance) { |
23 } | 23 } |
24 | 24 |
25 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { | 25 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { |
26 if (position.size() == last_size_) | 26 if (position.size() == last_size_) |
27 return; | 27 return; |
28 last_size_ = position.size(); | 28 last_size_ = position.size(); |
29 | 29 |
30 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, last_size_, true); | 30 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, last_size_, true); |
31 pp::Graphics2D graphics(this, last_size_, false); | 31 pp::Graphics2D graphics(this, last_size_, false); |
32 BindGraphics(graphics); | 32 BindGraphics(graphics); |
33 | 33 |
34 pp::FontDescription_Dev desc; | 34 pp::BrowserFontDescription desc; |
35 desc.set_family(PP_FONTFAMILY_SANSSERIF); | 35 desc.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF); |
36 desc.set_size(100); | 36 desc.set_size(100); |
37 pp::Font_Dev font(this, desc); | 37 pp::BrowserFont_Trusted font(this, desc); |
38 | 38 |
39 // Draw some large, alpha blended text, including Arabic shaping. | 39 // Draw some large, alpha blended text, including Arabic shaping. |
40 pp::Rect text_clip(position.size()); // Use entire bounds for clip. | 40 pp::Rect text_clip(position.size()); // Use entire bounds for clip. |
41 font.DrawTextAt(&image, | 41 font.DrawTextAt(&image, |
42 pp::TextRun_Dev("\xD9\x85\xD8\xB1\xD8\xAD\xD8\xA8\xD8\xA7\xE2\x80\x8E", | 42 pp::BrowserFontTextRun( |
43 true, true), | 43 "\xD9\x85\xD8\xB1\xD8\xAD\xD8\xA8\xD8\xA7\xE2\x80\x8E", true, true), |
44 pp::Point(20, 100), 0x80008000, clip, false); | 44 pp::Point(20, 100), 0x80008000, clip, false); |
45 | 45 |
46 // Draw the default font names and sizes. | 46 // Draw the default font names and sizes. |
47 int y = 160; | 47 int y = 160; |
48 { | 48 { |
49 pp::FontDescription_Dev desc; | 49 pp::BrowserFontDescription desc; |
50 pp::Font_Dev default_font(this, desc); | 50 pp::BrowserFont_Trusted default_font(this, desc); |
51 default_font.DrawSimpleText( | 51 default_font.DrawSimpleText( |
52 &image, DescribeFont(default_font, "Default font"), | 52 &image, DescribeFont(default_font, "Default font"), |
53 pp::Point(10, y), 0xFF000000); | 53 pp::Point(10, y), 0xFF000000); |
54 y += 20; | 54 y += 20; |
55 } | 55 } |
56 { | 56 { |
57 pp::FontDescription_Dev desc; | 57 pp::BrowserFontDescription desc; |
58 desc.set_family(PP_FONTFAMILY_SERIF); | 58 desc.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SERIF); |
59 pp::Font_Dev serif_font(this, desc); | 59 pp::BrowserFont_Trusted serif_font(this, desc); |
60 serif_font.DrawSimpleText( | 60 serif_font.DrawSimpleText( |
61 &image, DescribeFont(serif_font, "Serif font"), | 61 &image, DescribeFont(serif_font, "Serif font"), |
62 pp::Point(10, y), 0xFF000000); | 62 pp::Point(10, y), 0xFF000000); |
63 y += 20; | 63 y += 20; |
64 } | 64 } |
65 { | 65 { |
66 pp::FontDescription_Dev desc; | 66 pp::BrowserFontDescription desc; |
67 desc.set_family(PP_FONTFAMILY_SANSSERIF); | 67 desc.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF); |
68 pp::Font_Dev sans_serif_font(this, desc); | 68 pp::BrowserFont_Trusted sans_serif_font(this, desc); |
69 sans_serif_font.DrawSimpleText( | 69 sans_serif_font.DrawSimpleText( |
70 &image, DescribeFont(sans_serif_font, "Sans serif font"), | 70 &image, DescribeFont(sans_serif_font, "Sans serif font"), |
71 pp::Point(10, y), 0xFF000000); | 71 pp::Point(10, y), 0xFF000000); |
72 y += 20; | 72 y += 20; |
73 } | 73 } |
74 { | 74 { |
75 pp::FontDescription_Dev desc; | 75 pp::BrowserFontDescription desc; |
76 desc.set_family(PP_FONTFAMILY_MONOSPACE); | 76 desc.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE); |
77 pp::Font_Dev monospace_font(this, desc); | 77 pp::BrowserFont_Trusted monospace_font(this, desc); |
78 monospace_font.DrawSimpleText( | 78 monospace_font.DrawSimpleText( |
79 &image, DescribeFont(monospace_font, "Monospace font"), | 79 &image, DescribeFont(monospace_font, "Monospace font"), |
80 pp::Point(10, y), 0xFF000000); | 80 pp::Point(10, y), 0xFF000000); |
81 y += 20; | 81 y += 20; |
82 } | 82 } |
83 | 83 |
84 graphics.PaintImageData(image, pp::Point(0, 0)); | 84 graphics.PaintImageData(image, pp::Point(0, 0)); |
85 graphics.Flush(pp::CompletionCallback(&DummyCompletionCallback, NULL)); | 85 graphics.Flush(pp::CompletionCallback(&DummyCompletionCallback, NULL)); |
86 } | 86 } |
87 | 87 |
88 private: | 88 private: |
89 // Returns a string describing the given font, using the given title. | 89 // Returns a string describing the given font, using the given title. |
90 std::string DescribeFont(const pp::Font_Dev& font, const char* title) { | 90 std::string DescribeFont(const pp::BrowserFont_Trusted& font, |
91 pp::FontDescription_Dev desc; | 91 const char* title) { |
92 PP_FontMetrics_Dev metrics; | 92 pp::BrowserFontDescription desc; |
| 93 PP_BrowserFont_Trusted_Metrics metrics; |
93 font.Describe(&desc, &metrics); | 94 font.Describe(&desc, &metrics); |
94 | 95 |
95 char buf[256]; | 96 char buf[256]; |
96 sprintf(buf, "%s = %s %dpt", | 97 sprintf(buf, "%s = %s %dpt", |
97 title, desc.face().AsString().c_str(), desc.size()); | 98 title, desc.face().AsString().c_str(), desc.size()); |
98 return std::string(buf); | 99 return std::string(buf); |
99 } | 100 } |
100 | 101 |
101 pp::Size last_size_; | 102 pp::Size last_size_; |
102 }; | 103 }; |
103 | 104 |
104 class MyModule : public pp::Module { | 105 class MyModule : public pp::Module { |
105 public: | 106 public: |
106 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 107 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
107 return new MyInstance(instance); | 108 return new MyInstance(instance); |
108 } | 109 } |
109 }; | 110 }; |
110 | 111 |
111 namespace pp { | 112 namespace pp { |
112 | 113 |
113 // Factory function for your specialization of the Module object. | 114 // Factory function for your specialization of the Module object. |
114 Module* CreateModule() { | 115 Module* CreateModule() { |
115 return new MyModule(); | 116 return new MyModule(); |
116 } | 117 } |
117 | 118 |
118 } // namespace pp | 119 } // namespace pp |
OLD | NEW |