| 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/common.h" |
| 10 #include "ppapi/cpp/image_data.h" | 10 #include "ppapi/cpp/image_data.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 set_small_caps(other.small_caps()); | 43 set_small_caps(other.small_caps()); |
| 44 set_letter_spacing(other.letter_spacing()); | 44 set_letter_spacing(other.letter_spacing()); |
| 45 set_word_spacing(other.word_spacing()); | 45 set_word_spacing(other.word_spacing()); |
| 46 } | 46 } |
| 47 | 47 |
| 48 FontDescription_Dev::~FontDescription_Dev() { | 48 FontDescription_Dev::~FontDescription_Dev() { |
| 49 } | 49 } |
| 50 | 50 |
| 51 FontDescription_Dev& FontDescription_Dev::operator=( | 51 FontDescription_Dev& FontDescription_Dev::operator=( |
| 52 const FontDescription_Dev& other) { | 52 const FontDescription_Dev& other) { |
| 53 FontDescription_Dev copy(other); | 53 pp_font_description_ = other.pp_font_description_; |
| 54 swap(copy); | 54 |
| 55 // Be careful about the refcount of the string, the copy that operator= made |
| 56 // above didn't copy a ref. |
| 57 pp_font_description_.face = PP_MakeUndefined(); |
| 58 set_face(other.face()); |
| 59 |
| 55 return *this; | 60 return *this; |
| 56 } | 61 } |
| 57 | 62 |
| 58 void FontDescription_Dev::swap(FontDescription_Dev& other) { | |
| 59 // Need to fix up both the face and the pp_font_description_.face which the | |
| 60 // setter does for us. | |
| 61 Var temp = face(); | |
| 62 set_face(other.face()); | |
| 63 other.set_face(temp); | |
| 64 | |
| 65 std::swap(pp_font_description_.family, other.pp_font_description_.family); | |
| 66 std::swap(pp_font_description_.size, other.pp_font_description_.size); | |
| 67 std::swap(pp_font_description_.weight, other.pp_font_description_.weight); | |
| 68 std::swap(pp_font_description_.italic, other.pp_font_description_.italic); | |
| 69 std::swap(pp_font_description_.small_caps, | |
| 70 other.pp_font_description_.small_caps); | |
| 71 std::swap(pp_font_description_.letter_spacing, | |
| 72 other.pp_font_description_.letter_spacing); | |
| 73 std::swap(pp_font_description_.word_spacing, | |
| 74 other.pp_font_description_.word_spacing); | |
| 75 } | |
| 76 | |
| 77 // TextRun_Dev ----------------------------------------------------------------- | 63 // TextRun_Dev ----------------------------------------------------------------- |
| 78 | 64 |
| 79 TextRun_Dev::TextRun_Dev() { | 65 TextRun_Dev::TextRun_Dev() { |
| 80 pp_text_run_.text = text_.pp_var(); | 66 pp_text_run_.text = text_.pp_var(); |
| 81 pp_text_run_.rtl = PP_FALSE; | 67 pp_text_run_.rtl = PP_FALSE; |
| 82 pp_text_run_.override_direction = PP_FALSE; | 68 pp_text_run_.override_direction = PP_FALSE; |
| 83 } | 69 } |
| 84 | 70 |
| 85 TextRun_Dev::TextRun_Dev(const std::string& text, | 71 TextRun_Dev::TextRun_Dev(const std::string& text, |
| 86 bool rtl, | 72 bool rtl, |
| 87 bool override_direction) | 73 bool override_direction) |
| 88 : text_(text) { | 74 : text_(text) { |
| 89 pp_text_run_.text = text_.pp_var(); | 75 pp_text_run_.text = text_.pp_var(); |
| 90 pp_text_run_.rtl = BoolToPPBool(rtl); | 76 pp_text_run_.rtl = BoolToPPBool(rtl); |
| 91 pp_text_run_.override_direction = BoolToPPBool(override_direction); | 77 pp_text_run_.override_direction = BoolToPPBool(override_direction); |
| 92 } | 78 } |
| 93 | 79 |
| 94 TextRun_Dev::TextRun_Dev(const TextRun_Dev& other) : text_(other.text_) { | 80 TextRun_Dev::TextRun_Dev(const TextRun_Dev& other) : text_(other.text_) { |
| 95 pp_text_run_.text = text_.pp_var(); | 81 pp_text_run_.text = text_.pp_var(); |
| 96 pp_text_run_.rtl = other.pp_text_run_.rtl; | 82 pp_text_run_.rtl = other.pp_text_run_.rtl; |
| 97 pp_text_run_.override_direction = other.pp_text_run_.override_direction; | 83 pp_text_run_.override_direction = other.pp_text_run_.override_direction; |
| 98 } | 84 } |
| 99 | 85 |
| 100 TextRun_Dev::~TextRun_Dev() { | 86 TextRun_Dev::~TextRun_Dev() { |
| 101 } | 87 } |
| 102 | 88 |
| 103 TextRun_Dev& TextRun_Dev::operator=(const TextRun_Dev& other) { | 89 TextRun_Dev& TextRun_Dev::operator=(const TextRun_Dev& other) { |
| 104 TextRun_Dev copy(other); | 90 pp_text_run_ = other.pp_text_run_; |
| 105 swap(copy); | 91 text_ = other.text_; |
| 92 pp_text_run_.text = text_.pp_var(); |
| 106 return *this; | 93 return *this; |
| 107 } | 94 } |
| 108 | 95 |
| 109 void TextRun_Dev::swap(TextRun_Dev& other) { | |
| 110 std::swap(text_, other.text_); | |
| 111 | |
| 112 // Fix up both object's pp_text_run.text to point to their text_ member. | |
| 113 pp_text_run_.text = text_.pp_var(); | |
| 114 other.pp_text_run_.text = other.text_.pp_var(); | |
| 115 | |
| 116 std::swap(pp_text_run_.rtl, other.pp_text_run_.rtl); | |
| 117 std::swap(pp_text_run_.override_direction, | |
| 118 other.pp_text_run_.override_direction); | |
| 119 } | |
| 120 | |
| 121 // Font ------------------------------------------------------------------------ | 96 // Font ------------------------------------------------------------------------ |
| 122 | 97 |
| 123 Font_Dev::Font_Dev(PP_Resource resource) : Resource(resource) { | 98 Font_Dev::Font_Dev(PP_Resource resource) : Resource(resource) { |
| 124 } | 99 } |
| 125 | 100 |
| 126 Font_Dev::Font_Dev(const FontDescription_Dev& description) { | 101 Font_Dev::Font_Dev(const FontDescription_Dev& description) { |
| 127 if (!font_f) | 102 if (!font_f) |
| 128 return; | 103 return; |
| 129 PassRefFromConstructor(font_f->Create( | 104 PassRefFromConstructor(font_f->Create( |
| 130 Module::Get()->pp_module(), &description.pp_font_description())); | 105 Module::Get()->pp_module(), &description.pp_font_description())); |
| 131 } | 106 } |
| 132 | 107 |
| 133 Font_Dev::Font_Dev(const Font_Dev& other) : Resource(other) { | 108 Font_Dev::Font_Dev(const Font_Dev& other) : Resource(other) { |
| 134 } | 109 } |
| 135 | 110 |
| 136 Font_Dev& Font_Dev::operator=(const Font_Dev& other) { | 111 Font_Dev& Font_Dev::operator=(const Font_Dev& other) { |
| 137 Font_Dev copy(other); | 112 Resource::operator=(other); |
| 138 swap(copy); | |
| 139 return *this; | 113 return *this; |
| 140 } | 114 } |
| 141 | 115 |
| 142 void Font_Dev::swap(Font_Dev& other) { | |
| 143 Resource::swap(other); | |
| 144 } | |
| 145 | |
| 146 bool Font_Dev::Describe(FontDescription_Dev* description, | 116 bool Font_Dev::Describe(FontDescription_Dev* description, |
| 147 PP_FontMetrics_Dev* metrics) const { | 117 PP_FontMetrics_Dev* metrics) const { |
| 148 if (!font_f) | 118 if (!font_f) |
| 149 return false; | 119 return false; |
| 150 | 120 |
| 151 // Be careful with ownership of the |face| string. It will come back with | 121 // Be careful with ownership of the |face| string. It will come back with |
| 152 // a ref of 1, which we want to assign to the |face_| member of the C++ class. | 122 // a ref of 1, which we want to assign to the |face_| member of the C++ class. |
| 153 if (!font_f->Describe(pp_resource(), &description->pp_font_description_, | 123 if (!font_f->Describe(pp_resource(), &description->pp_font_description_, |
| 154 metrics)) | 124 metrics)) |
| 155 return false; | 125 return false; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 bool image_data_is_opaque) const { | 176 bool image_data_is_opaque) const { |
| 207 return DrawTextAt(dest, TextRun_Dev(text), position, color, | 177 return DrawTextAt(dest, TextRun_Dev(text), position, color, |
| 208 Rect(dest->size()), image_data_is_opaque); | 178 Rect(dest->size()), image_data_is_opaque); |
| 209 } | 179 } |
| 210 | 180 |
| 211 int32_t Font_Dev::MeasureSimpleText(const std::string& text) const { | 181 int32_t Font_Dev::MeasureSimpleText(const std::string& text) const { |
| 212 return MeasureText(TextRun_Dev(text)); | 182 return MeasureText(TextRun_Dev(text)); |
| 213 } | 183 } |
| 214 | 184 |
| 215 } // namespace pp | 185 } // namespace pp |
| OLD | NEW |