Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: third_party/WebKit/Source/core/layout/svg/SVGTextQuery.cpp

Issue 2888623008: Remove SVGTextMetrics Width/Height getters (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/SVGTextMetrics.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 10 matching lines...) Expand all
21 21
22 #include <algorithm> 22 #include <algorithm>
23 #include "core/layout/LayoutBlockFlow.h" 23 #include "core/layout/LayoutBlockFlow.h"
24 #include "core/layout/LayoutInline.h" 24 #include "core/layout/LayoutInline.h"
25 #include "core/layout/api/LineLayoutSVGInlineText.h" 25 #include "core/layout/api/LineLayoutSVGInlineText.h"
26 #include "core/layout/line/InlineFlowBox.h" 26 #include "core/layout/line/InlineFlowBox.h"
27 #include "core/layout/svg/LayoutSVGInlineText.h" 27 #include "core/layout/svg/LayoutSVGInlineText.h"
28 #include "core/layout/svg/SVGTextFragment.h" 28 #include "core/layout/svg/SVGTextFragment.h"
29 #include "core/layout/svg/SVGTextMetrics.h" 29 #include "core/layout/svg/SVGTextMetrics.h"
30 #include "core/layout/svg/line/SVGInlineTextBox.h" 30 #include "core/layout/svg/line/SVGInlineTextBox.h"
31 #include "platform/wtf/MathExtras.h"
32 #include "platform/wtf/Vector.h" 31 #include "platform/wtf/Vector.h"
33 32
34 namespace blink { 33 namespace blink {
35 34
36 // Base structure for callback user data 35 // Base structure for callback user data
37 struct QueryData { 36 struct QueryData {
38 QueryData() 37 QueryData()
39 : is_vertical_text(false), 38 : is_vertical_text(false),
40 current_offset(0), 39 current_offset(0),
41 text_line_layout(nullptr), 40 text_line_layout(nullptr),
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 250
252 static float CalculateGlyphRange(const QueryData* query_data, 251 static float CalculateGlyphRange(const QueryData* query_data,
253 const SVGTextFragment& fragment, 252 const SVGTextFragment& fragment,
254 unsigned start, 253 unsigned start,
255 unsigned end) { 254 unsigned end) {
256 const MetricsList& metrics_list = query_data->text_line_layout.MetricsList(); 255 const MetricsList& metrics_list = query_data->text_line_layout.MetricsList();
257 auto metrics = FindMetricsForCharacter(metrics_list, fragment, start); 256 auto metrics = FindMetricsForCharacter(metrics_list, fragment, start);
258 auto end_metrics = FindMetricsForCharacter(metrics_list, fragment, end); 257 auto end_metrics = FindMetricsForCharacter(metrics_list, fragment, end);
259 float glyph_range = 0; 258 float glyph_range = 0;
260 for (; metrics != end_metrics; ++metrics) 259 for (; metrics != end_metrics; ++metrics)
261 glyph_range += 260 glyph_range += metrics->Advance(query_data->is_vertical_text);
262 query_data->is_vertical_text ? metrics->Height() : metrics->Width();
263 return glyph_range; 261 return glyph_range;
264 } 262 }
265 263
266 // subStringLength() implementation 264 // subStringLength() implementation
267 struct SubStringLengthData : QueryData { 265 struct SubStringLengthData : QueryData {
268 SubStringLengthData(unsigned query_start_position, unsigned query_length) 266 SubStringLengthData(unsigned query_start_position, unsigned query_length)
269 : start_position(query_start_position), 267 : start_position(query_start_position),
270 length(query_length), 268 length(query_length),
271 sub_string_length(0) {} 269 sub_string_length(0) {}
272 270
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 struct ExtentOfCharacterData : QueryData { 438 struct ExtentOfCharacterData : QueryData {
441 ExtentOfCharacterData(unsigned query_position) : position(query_position) {} 439 ExtentOfCharacterData(unsigned query_position) : position(query_position) {}
442 440
443 unsigned position; 441 unsigned position;
444 FloatRect extent; 442 FloatRect extent;
445 }; 443 };
446 444
447 static FloatRect PhysicalGlyphExtents(const QueryData* query_data, 445 static FloatRect PhysicalGlyphExtents(const QueryData* query_data,
448 const SVGTextMetrics& metrics, 446 const SVGTextMetrics& metrics,
449 const FloatPoint& glyph_position) { 447 const FloatPoint& glyph_position) {
450 // TODO(fs): Negative glyph extents seems kind of weird to have, but 448 FloatRect glyph_extents(glyph_position, metrics.Extents());
451 // presently it can occur in some cases (like Arabic.)
452 FloatRect glyph_extents(glyph_position,
453 FloatSize(std::max<float>(metrics.Width(), 0),
454 std::max<float>(metrics.Height(), 0)));
455 449
456 // If RTL, adjust the starting point to align with the LHS of the glyph 450 // If RTL, adjust the starting point to align with the LHS of the glyph
457 // bounding box. 451 // bounding box.
458 if (!query_data->text_box->IsLeftToRightDirection()) { 452 if (!query_data->text_box->IsLeftToRightDirection()) {
459 if (query_data->is_vertical_text) 453 if (query_data->is_vertical_text)
460 glyph_extents.Move(0, -glyph_extents.Height()); 454 glyph_extents.Move(0, -glyph_extents.Height());
461 else 455 else
462 glyph_extents.Move(-glyph_extents.Width(), 0); 456 glyph_extents.Move(-glyph_extents.Width(), 0);
463 } 457 }
464 return glyph_extents; 458 return glyph_extents;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 if (extent.Contains(data->position)) { 608 if (extent.Contains(data->position)) {
615 // Compute the character offset of the glyph within the text node. 609 // Compute the character offset of the glyph within the text node.
616 unsigned offset_in_box = fragment.character_offset - 610 unsigned offset_in_box = fragment.character_offset -
617 query_data->text_box->Start() + fragment_offset; 611 query_data->text_box->Start() + fragment_offset;
618 data->offset_in_text_node = LogicalOffsetInTextNode( 612 data->offset_in_text_node = LogicalOffsetInTextNode(
619 query_data->text_line_layout, query_data->text_box, offset_in_box); 613 query_data->text_line_layout, query_data->text_box, offset_in_box);
620 data->hit_layout_item = LineLayoutItem(data->text_line_layout); 614 data->hit_layout_item = LineLayoutItem(data->text_line_layout);
621 return true; 615 return true;
622 } 616 }
623 fragment_offset += metrics->length(); 617 fragment_offset += metrics->length();
624 glyph_offset += 618 glyph_offset += metrics->Advance(data->is_vertical_text);
625 data->is_vertical_text ? metrics->Height() : metrics->Width();
626 ++metrics; 619 ++metrics;
627 } 620 }
628 return false; 621 return false;
629 } 622 }
630 623
631 int SVGTextQuery::CharacterNumberAtPosition(const FloatPoint& position) const { 624 int SVGTextQuery::CharacterNumberAtPosition(const FloatPoint& position) const {
632 CharacterNumberAtPositionData data(position); 625 CharacterNumberAtPositionData data(position);
633 SpatialQuery(query_root_layout_object_, &data, 626 SpatialQuery(query_root_layout_object_, &data,
634 CharacterNumberAtPositionCallback); 627 CharacterNumberAtPositionCallback);
635 return data.CharacterNumberWithin(query_root_layout_object_); 628 return data.CharacterNumberWithin(query_root_layout_object_);
636 } 629 }
637 630
638 } // namespace blink 631 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/SVGTextMetrics.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698