| 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/image_data.h" | 9 #include "ppapi/cpp/image_data.h" |
| 10 #include "ppapi/cpp/instance.h" | 10 #include "ppapi/cpp/instance_handle.h" |
| 11 #include "ppapi/cpp/point.h" | 11 #include "ppapi/cpp/point.h" |
| 12 #include "ppapi/cpp/rect.h" | 12 #include "ppapi/cpp/rect.h" |
| 13 #include "ppapi/cpp/module_impl.h" | 13 #include "ppapi/cpp/module_impl.h" |
| 14 | 14 |
| 15 namespace pp { | 15 namespace pp { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 template <> const char* interface_name<PPB_Font_Dev>() { | 19 template <> const char* interface_name<PPB_Font_Dev>() { |
| 20 return PPB_FONT_DEV_INTERFACE; | 20 return PPB_FONT_DEV_INTERFACE; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Font ------------------------------------------------------------------------ | 97 // Font ------------------------------------------------------------------------ |
| 98 | 98 |
| 99 Font_Dev::Font_Dev() : Resource() { | 99 Font_Dev::Font_Dev() : Resource() { |
| 100 } | 100 } |
| 101 | 101 |
| 102 Font_Dev::Font_Dev(PP_Resource resource) : Resource(resource) { | 102 Font_Dev::Font_Dev(PP_Resource resource) : Resource(resource) { |
| 103 } | 103 } |
| 104 | 104 |
| 105 Font_Dev::Font_Dev(Instance* instance, const FontDescription_Dev& description) { | 105 Font_Dev::Font_Dev(const InstanceHandle& instance, |
| 106 const FontDescription_Dev& description) { |
| 106 if (!has_interface<PPB_Font_Dev>()) | 107 if (!has_interface<PPB_Font_Dev>()) |
| 107 return; | 108 return; |
| 108 PassRefFromConstructor(get_interface<PPB_Font_Dev>()->Create( | 109 PassRefFromConstructor(get_interface<PPB_Font_Dev>()->Create( |
| 109 instance->pp_instance(), &description.pp_font_description())); | 110 instance.pp_instance(), &description.pp_font_description())); |
| 110 } | 111 } |
| 111 | 112 |
| 112 Font_Dev::Font_Dev(const Font_Dev& other) : Resource(other) { | 113 Font_Dev::Font_Dev(const Font_Dev& other) : Resource(other) { |
| 113 } | 114 } |
| 114 | 115 |
| 115 Font_Dev& Font_Dev::operator=(const Font_Dev& other) { | 116 Font_Dev& Font_Dev::operator=(const Font_Dev& other) { |
| 116 Resource::operator=(other); | 117 Resource::operator=(other); |
| 117 return *this; | 118 return *this; |
| 118 } | 119 } |
| 119 | 120 |
| 120 // static | 121 // static |
| 121 Var Font_Dev::GetFontFamilies(Instance* instance) { | 122 Var Font_Dev::GetFontFamilies(const InstanceHandle& instance) { |
| 122 if (!has_interface<PPB_Font_Dev>()) | 123 if (!has_interface<PPB_Font_Dev>()) |
| 123 return Var(); | 124 return Var(); |
| 124 return Var(Var::PassRef(), | 125 return Var(PASS_REF, get_interface<PPB_Font_Dev>()->GetFontFamilies( |
| 125 get_interface<PPB_Font_Dev>()->GetFontFamilies( | 126 instance.pp_instance())); |
| 126 instance->pp_instance())); | |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool Font_Dev::Describe(FontDescription_Dev* description, | 129 bool Font_Dev::Describe(FontDescription_Dev* description, |
| 130 PP_FontMetrics_Dev* metrics) const { | 130 PP_FontMetrics_Dev* metrics) const { |
| 131 if (!has_interface<PPB_Font_Dev>()) | 131 if (!has_interface<PPB_Font_Dev>()) |
| 132 return false; | 132 return false; |
| 133 | 133 |
| 134 // Be careful with ownership of the |face| string. It will come back with | 134 // Be careful with ownership of the |face| string. It will come back with |
| 135 // a ref of 1, which we want to assign to the |face_| member of the C++ class. | 135 // a ref of 1, which we want to assign to the |face_| member of the C++ class. |
| 136 if (!get_interface<PPB_Font_Dev>()->Describe( | 136 if (!get_interface<PPB_Font_Dev>()->Describe( |
| 137 pp_resource(), &description->pp_font_description_, metrics)) | 137 pp_resource(), &description->pp_font_description_, metrics)) |
| 138 return false; | 138 return false; |
| 139 description->face_ = Var(Var::PassRef(), | 139 description->face_ = Var(PASS_REF, |
| 140 description->pp_font_description_.face); | 140 description->pp_font_description_.face); |
| 141 | 141 |
| 142 return true; | 142 return true; |
| 143 } | 143 } |
| 144 | 144 |
| 145 bool Font_Dev::DrawTextAt(ImageData* dest, | 145 bool Font_Dev::DrawTextAt(ImageData* dest, |
| 146 const TextRun_Dev& text, | 146 const TextRun_Dev& text, |
| 147 const Point& position, | 147 const Point& position, |
| 148 uint32_t color, | 148 uint32_t color, |
| 149 const Rect& clip, | 149 const Rect& clip, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 bool image_data_is_opaque) const { | 191 bool image_data_is_opaque) const { |
| 192 return DrawTextAt(dest, TextRun_Dev(text), position, color, | 192 return DrawTextAt(dest, TextRun_Dev(text), position, color, |
| 193 Rect(dest->size()), image_data_is_opaque); | 193 Rect(dest->size()), image_data_is_opaque); |
| 194 } | 194 } |
| 195 | 195 |
| 196 int32_t Font_Dev::MeasureSimpleText(const std::string& text) const { | 196 int32_t Font_Dev::MeasureSimpleText(const std::string& text) const { |
| 197 return MeasureText(TextRun_Dev(text)); | 197 return MeasureText(TextRun_Dev(text)); |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace pp | 200 } // namespace pp |
| OLD | NEW |