Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 Google Inc. All rights reserved. | 2 * Copyright (c) 2012 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. | 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 return position; | 100 return position; |
| 101 } | 101 } |
| 102 | 102 |
| 103 int ShapeResult::RunInfo::CharacterIndexForXPosition( | 103 int ShapeResult::RunInfo::CharacterIndexForXPosition( |
| 104 float target_x, | 104 float target_x, |
| 105 bool include_partial_glyphs) const { | 105 bool include_partial_glyphs) const { |
| 106 DCHECK(target_x >= 0 && target_x <= width_); | 106 DCHECK(target_x >= 0 && target_x <= width_); |
| 107 if (target_x <= 0) | |
| 108 return !Rtl() ? 0 : num_characters_; | |
| 107 const unsigned num_glyphs = glyph_data_.size(); | 109 const unsigned num_glyphs = glyph_data_.size(); |
| 108 float current_x = 0; | 110 float current_x = 0; |
| 109 float current_advance = 0; | 111 float current_advance = 0; |
| 110 unsigned glyph_index = 0; | 112 unsigned glyph_index = 0; |
| 111 unsigned prev_character_index = num_characters_; // used only when rtl() | 113 unsigned prev_character_index = num_characters_; // used only when rtl() |
| 112 | 114 |
| 113 while (glyph_index < num_glyphs) { | 115 while (glyph_index < num_glyphs) { |
| 114 float prev_advance = current_advance; | 116 float prev_advance = current_advance; |
| 115 unsigned current_character_index = glyph_data_[glyph_index].character_index; | 117 unsigned current_character_index = glyph_data_[glyph_index].character_index; |
| 116 current_advance = glyph_data_[glyph_index].advance; | 118 current_advance = glyph_data_[glyph_index].advance; |
| 117 while (glyph_index < num_glyphs - 1 && | 119 while (glyph_index < num_glyphs - 1 && |
| 118 current_character_index == | 120 current_character_index == |
| 119 glyph_data_[glyph_index + 1].character_index) | 121 glyph_data_[glyph_index + 1].character_index) |
| 120 current_advance += glyph_data_[++glyph_index].advance; | 122 current_advance += glyph_data_[++glyph_index].advance; |
| 121 float next_x; | 123 float next_x; |
| 122 if (include_partial_glyphs) { | 124 if (include_partial_glyphs) { |
| 123 // For hit testing, find the closest caret point by incuding | 125 // For hit testing, find the closest caret point by incuding |
| 124 // end-half of the previous character and start-half of the current | 126 // end-half of the previous character and start-half of the current |
| 125 // character. | 127 // character. |
| 126 current_advance = current_advance / 2.0; | 128 current_advance = current_advance / 2.0; |
| 127 next_x = current_x + prev_advance + current_advance; | 129 next_x = current_x + prev_advance + current_advance; |
| 130 // When include_partial_glyphs, "<=" or "<" is not a big deal because | |
| 131 // |next_x| is not at the character boundary. | |
| 132 if (target_x <= next_x) | |
| 133 return Rtl() ? prev_character_index : current_character_index; | |
| 128 } else { | 134 } else { |
| 129 next_x = current_x + current_advance; | 135 next_x = current_x + current_advance; |
| 136 if (!Rtl()) { | |
|
eae
2017/06/06 00:03:54
How about
static bool targetPastEdge(bool rtl, fl
| |
| 137 // In LTR, the edge belongs to the character on right. | |
| 138 if (target_x < next_x) | |
| 139 return current_character_index; | |
| 140 } else { | |
| 141 // In RTL, the edge belongs to the character on left. | |
| 142 if (target_x <= next_x) | |
| 143 return current_character_index; | |
| 144 } | |
| 130 } | 145 } |
| 131 if (current_x <= target_x && target_x <= next_x) | |
| 132 return include_partial_glyphs && Rtl() ? prev_character_index | |
| 133 : current_character_index; | |
| 134 current_x = next_x; | 146 current_x = next_x; |
| 135 prev_character_index = current_character_index; | 147 prev_character_index = current_character_index; |
| 136 ++glyph_index; | 148 ++glyph_index; |
| 137 } | 149 } |
| 138 | 150 |
| 139 return Rtl() ? 0 : num_characters_; | 151 return Rtl() ? 0 : num_characters_; |
| 140 } | 152 } |
| 141 | 153 |
| 142 void ShapeResult::RunInfo::SetGlyphAndPositions(unsigned index, | 154 void ShapeResult::RunInfo::SetGlyphAndPositions(unsigned index, |
| 143 uint16_t glyph_id, | 155 uint16_t glyph_id, |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 result->width_ = run->width_; | 497 result->width_ = run->width_; |
| 486 result->num_glyphs_ = count; | 498 result->num_glyphs_ = count; |
| 487 DCHECK_EQ(result->num_glyphs_, count); // no overflow | 499 DCHECK_EQ(result->num_glyphs_, count); // no overflow |
| 488 result->has_vertical_offsets_ = | 500 result->has_vertical_offsets_ = |
| 489 font_data->PlatformData().IsVerticalAnyUpright(); | 501 font_data->PlatformData().IsVerticalAnyUpright(); |
| 490 result->runs_.push_back(std::move(run)); | 502 result->runs_.push_back(std::move(run)); |
| 491 return result.Release(); | 503 return result.Release(); |
| 492 } | 504 } |
| 493 | 505 |
| 494 } // namespace blink | 506 } // namespace blink |
| OLD | NEW |