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

Side by Side Diff: webkit/glue/plugins/pepper_font.cc

Issue 4310002: Make PPAPI headers compile with C compilers (gcc on Linux & Mac and MSVS on W... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/plugins/pepper_file_ref.cc ('k') | webkit/glue/plugins/pepper_graphics_2d.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "webkit/glue/plugins/pepper_font.h" 5 #include "webkit/glue/plugins/pepper_font.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "ppapi/c/dev/ppb_font_dev.h" 9 #include "ppapi/c/dev/ppb_font_dev.h"
10 #include "ppapi/c/pp_rect.h" 10 #include "ppapi/c/pp_rect.h"
11 #include "third_party/WebKit/WebKit/chromium/public/WebFont.h" 11 #include "third_party/WebKit/WebKit/chromium/public/WebFont.h"
12 #include "third_party/WebKit/WebKit/chromium/public/WebFontDescription.h" 12 #include "third_party/WebKit/WebKit/chromium/public/WebFontDescription.h"
13 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" 13 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
14 #include "third_party/WebKit/WebKit/chromium/public/WebFloatPoint.h" 14 #include "third_party/WebKit/WebKit/chromium/public/WebFloatPoint.h"
15 #include "third_party/WebKit/WebKit/chromium/public/WebFloatRect.h" 15 #include "third_party/WebKit/WebKit/chromium/public/WebFloatRect.h"
16 #include "third_party/WebKit/WebKit/chromium/public/WebTextRun.h" 16 #include "third_party/WebKit/WebKit/chromium/public/WebTextRun.h"
17 #include "webkit/glue/plugins/pepper_common.h"
17 #include "webkit/glue/plugins/pepper_image_data.h" 18 #include "webkit/glue/plugins/pepper_image_data.h"
18 #include "webkit/glue/plugins/pepper_plugin_module.h" 19 #include "webkit/glue/plugins/pepper_plugin_module.h"
19 #include "webkit/glue/plugins/pepper_string.h" 20 #include "webkit/glue/plugins/pepper_string.h"
20 #include "webkit/glue/plugins/pepper_var.h" 21 #include "webkit/glue/plugins/pepper_var.h"
21 #include "webkit/glue/webkit_glue.h" 22 #include "webkit/glue/webkit_glue.h"
22 23
23 using WebKit::WebFloatPoint; 24 using WebKit::WebFloatPoint;
24 using WebKit::WebFloatRect; 25 using WebKit::WebFloatRect;
25 using WebKit::WebFont; 26 using WebKit::WebFont;
26 using WebKit::WebFontDescription; 27 using WebKit::WebFontDescription;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace == 81 COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace ==
81 PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_MONOSPACE), 82 PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_MONOSPACE),
82 MonospaceFamily); 83 MonospaceFamily);
83 84
84 WebFontDescription result; 85 WebFontDescription result;
85 scoped_refptr<StringVar> face_name(StringVar::FromPPVar(font.face)); 86 scoped_refptr<StringVar> face_name(StringVar::FromPPVar(font.face));
86 if (face_name) 87 if (face_name)
87 result.family = UTF8ToUTF16(face_name->value()); 88 result.family = UTF8ToUTF16(face_name->value());
88 result.genericFamily = PP_FONTFAMILY_TO_WEB_FONTFAMILY(font.family); 89 result.genericFamily = PP_FONTFAMILY_TO_WEB_FONTFAMILY(font.family);
89 result.size = static_cast<float>(font.size); 90 result.size = static_cast<float>(font.size);
90 result.italic = font.italic; 91 result.italic = PPBoolToBool(font.italic);
91 result.smallCaps = font.small_caps; 92 result.smallCaps = PPBoolToBool(font.small_caps);
92 result.weight = static_cast<WebFontDescription::Weight>(font.weight); 93 result.weight = static_cast<WebFontDescription::Weight>(font.weight);
93 result.letterSpacing = static_cast<short>(font.letter_spacing); 94 result.letterSpacing = static_cast<short>(font.letter_spacing);
94 result.wordSpacing = static_cast<short>(font.word_spacing); 95 result.wordSpacing = static_cast<short>(font.word_spacing);
95 return result; 96 return result;
96 } 97 }
97 98
98 // Converts the given PP_TextRun to a WebTextRun, returning true on success. 99 // Converts the given PP_TextRun to a WebTextRun, returning true on success.
99 // False means the input was invalid. 100 // False means the input was invalid.
100 bool PPTextRunToWebTextRun(const PP_TextRun_Dev* run, WebTextRun* output) { 101 bool PPTextRunToWebTextRun(const PP_TextRun_Dev* run, WebTextRun* output) {
101 scoped_refptr<StringVar> text_string(StringVar::FromPPVar(run->text)); 102 scoped_refptr<StringVar> text_string(StringVar::FromPPVar(run->text));
102 if (!text_string) 103 if (!text_string)
103 return false; 104 return false;
104 *output = WebTextRun(UTF8ToUTF16(text_string->value()), 105 *output = WebTextRun(UTF8ToUTF16(text_string->value()),
105 run->rtl, run->override_direction); 106 PPBoolToBool(run->rtl),
107 PPBoolToBool(run->override_direction));
106 return true; 108 return true;
107 } 109 }
108 110
109 PP_Resource Create(PP_Module module_id, 111 PP_Resource Create(PP_Module module_id,
110 const PP_FontDescription_Dev* description) { 112 const PP_FontDescription_Dev* description) {
111 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); 113 PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
112 if (!module) 114 if (!module)
113 return 0; 115 return 0;
114 116
115 if (!IsPPFontDescriptionValid(*description)) 117 if (!IsPPFontDescriptionValid(*description))
116 return 0; 118 return 0;
117 119
118 scoped_refptr<Font> font(new Font(module, *description)); 120 scoped_refptr<Font> font(new Font(module, *description));
119 return font->GetReference(); 121 return font->GetReference();
120 } 122 }
121 123
122 bool IsFont(PP_Resource resource) { 124 PP_Bool IsFont(PP_Resource resource) {
123 return !!Resource::GetAs<Font>(resource).get(); 125 return BoolToPPBool(!!Resource::GetAs<Font>(resource).get());
124 } 126 }
125 127
126 bool Describe(PP_Resource font_id, 128 PP_Bool Describe(PP_Resource font_id,
127 PP_FontDescription_Dev* description, 129 PP_FontDescription_Dev* description,
128 PP_FontMetrics_Dev* metrics) { 130 PP_FontMetrics_Dev* metrics) {
129 scoped_refptr<Font> font(Resource::GetAs<Font>(font_id)); 131 scoped_refptr<Font> font(Resource::GetAs<Font>(font_id));
130 if (!font.get()) 132 if (!font.get())
131 return false; 133 return PP_FALSE;
132 return font->Describe(description, metrics); 134 return BoolToPPBool(font->Describe(description, metrics));
133 } 135 }
134 136
135 bool DrawTextAt(PP_Resource font_id, 137 PP_Bool DrawTextAt(PP_Resource font_id,
136 PP_Resource image_data, 138 PP_Resource image_data,
137 const PP_TextRun_Dev* text, 139 const PP_TextRun_Dev* text,
138 const PP_Point* position, 140 const PP_Point* position,
139 uint32_t color, 141 uint32_t color,
140 const PP_Rect* clip, 142 const PP_Rect* clip,
141 bool image_data_is_opaque) { 143 PP_Bool image_data_is_opaque) {
142 scoped_refptr<Font> font(Resource::GetAs<Font>(font_id)); 144 scoped_refptr<Font> font(Resource::GetAs<Font>(font_id));
143 if (!font.get()) 145 if (!font.get())
144 return false; 146 return PP_FALSE;
145 return font->DrawTextAt(image_data, text, position, color, clip, 147 return BoolToPPBool(font->DrawTextAt(image_data, text, position, color, clip,
146 image_data_is_opaque); 148 PPBoolToBool(image_data_is_opaque)));
147 } 149 }
148 150
149 int32_t MeasureText(PP_Resource font_id, const PP_TextRun_Dev* text) { 151 int32_t MeasureText(PP_Resource font_id, const PP_TextRun_Dev* text) {
150 scoped_refptr<Font> font(Resource::GetAs<Font>(font_id)); 152 scoped_refptr<Font> font(Resource::GetAs<Font>(font_id));
151 if (!font.get()) 153 if (!font.get())
152 return -1; 154 return -1;
153 return font->MeasureText(text); 155 return font->MeasureText(text);
154 } 156 }
155 157
156 uint32_t CharacterOffsetForPixel(PP_Resource font_id, 158 uint32_t CharacterOffsetForPixel(PP_Resource font_id,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 206
205 WebFontDescription web_desc = font_->fontDescription(); 207 WebFontDescription web_desc = font_->fontDescription();
206 208
207 // While converting the other way in PPFontDescToWebFontDesc we validated 209 // While converting the other way in PPFontDescToWebFontDesc we validated
208 // that the enums can be casted. 210 // that the enums can be casted.
209 description->face = StringVar::StringToPPVar(module(), 211 description->face = StringVar::StringToPPVar(module(),
210 UTF16ToUTF8(web_desc.family)); 212 UTF16ToUTF8(web_desc.family));
211 description->family = static_cast<PP_FontFamily_Dev>(web_desc.genericFamily); 213 description->family = static_cast<PP_FontFamily_Dev>(web_desc.genericFamily);
212 description->size = static_cast<uint32_t>(web_desc.size); 214 description->size = static_cast<uint32_t>(web_desc.size);
213 description->weight = static_cast<PP_FontWeight_Dev>(web_desc.weight); 215 description->weight = static_cast<PP_FontWeight_Dev>(web_desc.weight);
214 description->italic = web_desc.italic; 216 description->italic = BoolToPPBool(web_desc.italic);
215 description->small_caps = web_desc.smallCaps; 217 description->small_caps = BoolToPPBool(web_desc.smallCaps);
216 218
217 metrics->height = font_->height(); 219 metrics->height = font_->height();
218 metrics->ascent = font_->ascent(); 220 metrics->ascent = font_->ascent();
219 metrics->descent = font_->descent(); 221 metrics->descent = font_->descent();
220 metrics->line_spacing = font_->lineSpacing(); 222 metrics->line_spacing = font_->lineSpacing();
221 metrics->x_height = static_cast<int32_t>(font_->xHeight()); 223 metrics->x_height = static_cast<int32_t>(font_->xHeight());
222 224
223 return true; 225 return true;
224 } 226 }
225 227
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 return -1; 285 return -1;
284 if (char_offset >= run.text.length()) 286 if (char_offset >= run.text.length())
285 return -1; 287 return -1;
286 288
287 WebFloatRect rect = font_->selectionRectForText( 289 WebFloatRect rect = font_->selectionRectForText(
288 run, WebFloatPoint(0.0f, 0.0f), font_->height(), 0, char_offset); 290 run, WebFloatPoint(0.0f, 0.0f), font_->height(), 0, char_offset);
289 return static_cast<int>(rect.width); 291 return static_cast<int>(rect.width);
290 } 292 }
291 293
292 } // namespace pepper 294 } // namespace pepper
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_file_ref.cc ('k') | webkit/glue/plugins/pepper_graphics_2d.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698