| OLD | NEW |
| 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 "ppapi/cpp/dev/font_dev.h" | 5 #include "ppapi/cpp/dev/font_dev.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ppapi/cpp/common.h" |
| 9 #include "ppapi/cpp/image_data.h" | 10 #include "ppapi/cpp/image_data.h" |
| 10 #include "ppapi/cpp/module.h" | 11 #include "ppapi/cpp/module.h" |
| 11 #include "ppapi/cpp/point.h" | 12 #include "ppapi/cpp/point.h" |
| 12 #include "ppapi/cpp/rect.h" | 13 #include "ppapi/cpp/rect.h" |
| 13 #include "ppapi/cpp/module_impl.h" | 14 #include "ppapi/cpp/module_impl.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 DeviceFuncs<PPB_Font_Dev> font_f(PPB_FONT_DEV_INTERFACE); | 18 DeviceFuncs<PPB_Font_Dev> font_f(PPB_FONT_DEV_INTERFACE); |
| 18 | 19 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 std::swap(pp_font_description_.letter_spacing, | 71 std::swap(pp_font_description_.letter_spacing, |
| 71 other.pp_font_description_.letter_spacing); | 72 other.pp_font_description_.letter_spacing); |
| 72 std::swap(pp_font_description_.word_spacing, | 73 std::swap(pp_font_description_.word_spacing, |
| 73 other.pp_font_description_.word_spacing); | 74 other.pp_font_description_.word_spacing); |
| 74 } | 75 } |
| 75 | 76 |
| 76 // TextRun_Dev ----------------------------------------------------------------- | 77 // TextRun_Dev ----------------------------------------------------------------- |
| 77 | 78 |
| 78 TextRun_Dev::TextRun_Dev() { | 79 TextRun_Dev::TextRun_Dev() { |
| 79 pp_text_run_.text = text_.pp_var(); | 80 pp_text_run_.text = text_.pp_var(); |
| 80 pp_text_run_.rtl = false; | 81 pp_text_run_.rtl = PP_FALSE; |
| 81 pp_text_run_.override_direction = false; | 82 pp_text_run_.override_direction = PP_FALSE; |
| 82 } | 83 } |
| 83 | 84 |
| 84 TextRun_Dev::TextRun_Dev(const std::string& text, | 85 TextRun_Dev::TextRun_Dev(const std::string& text, |
| 85 bool rtl, | 86 bool rtl, |
| 86 bool override_direction) | 87 bool override_direction) |
| 87 : text_(text) { | 88 : text_(text) { |
| 88 pp_text_run_.text = text_.pp_var(); | 89 pp_text_run_.text = text_.pp_var(); |
| 89 pp_text_run_.rtl = rtl; | 90 pp_text_run_.rtl = BoolToPPBool(rtl); |
| 90 pp_text_run_.override_direction = override_direction; | 91 pp_text_run_.override_direction = BoolToPPBool(override_direction); |
| 91 } | 92 } |
| 92 | 93 |
| 93 TextRun_Dev::TextRun_Dev(const TextRun_Dev& other) : text_(other.text_) { | 94 TextRun_Dev::TextRun_Dev(const TextRun_Dev& other) : text_(other.text_) { |
| 94 pp_text_run_.text = text_.pp_var(); | 95 pp_text_run_.text = text_.pp_var(); |
| 95 pp_text_run_.rtl = other.pp_text_run_.rtl; | 96 pp_text_run_.rtl = other.pp_text_run_.rtl; |
| 96 pp_text_run_.override_direction = other.pp_text_run_.override_direction; | 97 pp_text_run_.override_direction = other.pp_text_run_.override_direction; |
| 97 } | 98 } |
| 98 | 99 |
| 99 TextRun_Dev::~TextRun_Dev() { | 100 TextRun_Dev::~TextRun_Dev() { |
| 100 } | 101 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 160 } |
| 160 | 161 |
| 161 bool Font_Dev::DrawTextAt(ImageData* dest, | 162 bool Font_Dev::DrawTextAt(ImageData* dest, |
| 162 const TextRun_Dev& text, | 163 const TextRun_Dev& text, |
| 163 const Point& position, | 164 const Point& position, |
| 164 uint32_t color, | 165 uint32_t color, |
| 165 const Rect& clip, | 166 const Rect& clip, |
| 166 bool image_data_is_opaque) const { | 167 bool image_data_is_opaque) const { |
| 167 if (!font_f) | 168 if (!font_f) |
| 168 return false; | 169 return false; |
| 169 return font_f->DrawTextAt(pp_resource(), dest->pp_resource(), | 170 return PPBoolToBool(font_f->DrawTextAt(pp_resource(), |
| 170 &text.pp_text_run(), &position.pp_point(), | 171 dest->pp_resource(), |
| 171 color, &clip.pp_rect(), image_data_is_opaque); | 172 &text.pp_text_run(), |
| 173 &position.pp_point(), |
| 174 color, |
| 175 &clip.pp_rect(), |
| 176 BoolToPPBool(image_data_is_opaque))); |
| 172 } | 177 } |
| 173 | 178 |
| 174 int32_t Font_Dev::MeasureText(const TextRun_Dev& text) const { | 179 int32_t Font_Dev::MeasureText(const TextRun_Dev& text) const { |
| 175 if (!font_f) | 180 if (!font_f) |
| 176 return -1; | 181 return -1; |
| 177 return font_f->MeasureText(pp_resource(), &text.pp_text_run()); | 182 return font_f->MeasureText(pp_resource(), &text.pp_text_run()); |
| 178 } | 183 } |
| 179 | 184 |
| 180 uint32_t Font_Dev::CharacterOffsetForPixel(const TextRun_Dev& text, | 185 uint32_t Font_Dev::CharacterOffsetForPixel(const TextRun_Dev& text, |
| 181 int32_t pixel_position) const { | 186 int32_t pixel_position) const { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 201 bool image_data_is_opaque) const { | 206 bool image_data_is_opaque) const { |
| 202 return DrawTextAt(dest, TextRun_Dev(text), position, color, | 207 return DrawTextAt(dest, TextRun_Dev(text), position, color, |
| 203 Rect(dest->size()), image_data_is_opaque); | 208 Rect(dest->size()), image_data_is_opaque); |
| 204 } | 209 } |
| 205 | 210 |
| 206 int32_t Font_Dev::MeasureSimpleText(const std::string& text) const { | 211 int32_t Font_Dev::MeasureSimpleText(const std::string& text) const { |
| 207 return MeasureText(TextRun_Dev(text)); | 212 return MeasureText(TextRun_Dev(text)); |
| 208 } | 213 } |
| 209 | 214 |
| 210 } // namespace pp | 215 } // namespace pp |
| OLD | NEW |