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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 data.offset = FloatSize(offsetX, offsetY); | 148 data.offset = FloatSize(offsetX, offsetY); |
149 } | 149 } |
150 | 150 |
151 ShapeResult::ShapeResult(const Font* font, | 151 ShapeResult::ShapeResult(const Font* font, |
152 unsigned numCharacters, | 152 unsigned numCharacters, |
153 TextDirection direction) | 153 TextDirection direction) |
154 : m_width(0), | 154 : m_width(0), |
155 m_primaryFont(const_cast<SimpleFontData*>(font->primaryFont())), | 155 m_primaryFont(const_cast<SimpleFontData*>(font->primaryFont())), |
156 m_numCharacters(numCharacters), | 156 m_numCharacters(numCharacters), |
157 m_numGlyphs(0), | 157 m_numGlyphs(0), |
158 m_direction(direction), | 158 m_direction(static_cast<unsigned>(direction)), |
159 m_hasVerticalOffsets(0) {} | 159 m_hasVerticalOffsets(0) {} |
160 | 160 |
161 ShapeResult::ShapeResult(const ShapeResult& other) | 161 ShapeResult::ShapeResult(const ShapeResult& other) |
162 : m_width(other.m_width), | 162 : m_width(other.m_width), |
163 m_glyphBoundingBox(other.m_glyphBoundingBox), | 163 m_glyphBoundingBox(other.m_glyphBoundingBox), |
164 m_primaryFont(other.m_primaryFont), | 164 m_primaryFont(other.m_primaryFont), |
165 m_numCharacters(other.m_numCharacters), | 165 m_numCharacters(other.m_numCharacters), |
166 m_numGlyphs(other.m_numGlyphs), | 166 m_numGlyphs(other.m_numGlyphs), |
167 m_direction(other.m_direction), | 167 m_direction(other.m_direction), |
168 m_hasVerticalOffsets(other.m_hasVerticalOffsets) { | 168 m_hasVerticalOffsets(other.m_hasVerticalOffsets) { |
(...skipping 10 matching lines...) Expand all Loading... |
179 selfByteSize += m_runs[i]->byteSize(); | 179 selfByteSize += m_runs[i]->byteSize(); |
180 } | 180 } |
181 return selfByteSize; | 181 return selfByteSize; |
182 } | 182 } |
183 | 183 |
184 int ShapeResult::offsetForPosition(float targetX, | 184 int ShapeResult::offsetForPosition(float targetX, |
185 bool includePartialGlyphs) const { | 185 bool includePartialGlyphs) const { |
186 int charactersSoFar = 0; | 186 int charactersSoFar = 0; |
187 float currentX = 0; | 187 float currentX = 0; |
188 | 188 |
189 if (m_direction == RTL) { | 189 if (rtl()) { |
190 charactersSoFar = m_numCharacters; | 190 charactersSoFar = m_numCharacters; |
191 for (unsigned i = 0; i < m_runs.size(); ++i) { | 191 for (unsigned i = 0; i < m_runs.size(); ++i) { |
192 if (!m_runs[i]) | 192 if (!m_runs[i]) |
193 continue; | 193 continue; |
194 charactersSoFar -= m_runs[i]->m_numCharacters; | 194 charactersSoFar -= m_runs[i]->m_numCharacters; |
195 float nextX = currentX + m_runs[i]->m_width; | 195 float nextX = currentX + m_runs[i]->m_width; |
196 float offsetForRun = targetX - currentX; | 196 float offsetForRun = targetX - currentX; |
197 if (offsetForRun >= 0 && offsetForRun <= m_runs[i]->m_width) { | 197 if (offsetForRun >= 0 && offsetForRun <= m_runs[i]->m_width) { |
198 // The x value in question is within this script run. | 198 // The x value in question is within this script run. |
199 const unsigned index = m_runs[i]->characterIndexForXPosition( | 199 const unsigned index = m_runs[i]->characterIndexForXPosition( |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 result->m_width = run->m_width; | 401 result->m_width = run->m_width; |
402 result->m_numGlyphs = count; | 402 result->m_numGlyphs = count; |
403 DCHECK_EQ(result->m_numGlyphs, count); // no overflow | 403 DCHECK_EQ(result->m_numGlyphs, count); // no overflow |
404 result->m_hasVerticalOffsets = | 404 result->m_hasVerticalOffsets = |
405 fontData->platformData().isVerticalAnyUpright(); | 405 fontData->platformData().isVerticalAnyUpright(); |
406 result->m_runs.append(std::move(run)); | 406 result->m_runs.append(std::move(run)); |
407 return result.release(); | 407 return result.release(); |
408 } | 408 } |
409 | 409 |
410 } // namespace blink | 410 } // namespace blink |
OLD | NEW |