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

Side by Side Diff: samples/swarm/swarm_ui_lib/view/MeasureText.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of view; 5 part of view;
6 6
7 // TODO(jacobr): handle splitting lines on symbols such as '-' that aren't 7 // TODO(jacobr): handle splitting lines on symbols such as '-' that aren't
8 // whitespace but are valid word breaking points. 8 // whitespace but are valid word breaking points.
9 /** 9 /**
10 * Utility class to efficiently word break and measure text without requiring 10 * Utility class to efficiently word break and measure text without requiring
(...skipping 27 matching lines...) Expand all
38 // full calculation. 38 // full calculation.
39 static bool isWhitespace(String character) { 39 static bool isWhitespace(String character) {
40 return character == ' ' || character == '\t' || character == '\n'; 40 return character == ' ' || character == '\t' || character == '\n';
41 } 41 }
42 42
43 num get typicalCharLength { 43 num get typicalCharLength {
44 return _typicalCharLength; 44 return _typicalCharLength;
45 } 45 }
46 46
47 String quickTruncate(String text, num lineWidth, int maxLines) { 47 String quickTruncate(String text, num lineWidth, int maxLines) {
48 int targetLength = (lineWidth * maxLines / _typicalCharLength).toInt(); 48 int targetLength = lineWidth * maxLines ~/ _typicalCharLength;
49 // Advance to next word break point. 49 // Advance to next word break point.
50 while(targetLength < text.length && !isWhitespace(text[targetLength])) { 50 while(targetLength < text.length && !isWhitespace(text[targetLength])) {
51 targetLength++; 51 targetLength++;
52 } 52 }
53 53
54 if (targetLength < text.length) { 54 if (targetLength < text.length) {
55 return '${text.substring(0, targetLength)}$ELLIPSIS'; 55 return '${text.substring(0, targetLength)}$ELLIPSIS';
56 } else { 56 } else {
57 return text; 57 return text;
58 } 58 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } else if (wordStartIndex == null && !whitespace) { 154 } else if (wordStartIndex == null && !whitespace) {
155 wordStartIndex = i; 155 wordStartIndex = i;
156 } 156 }
157 lastWhitespace = whitespace; 157 lastWhitespace = whitespace;
158 } 158 }
159 if (currentLength > 0) { 159 if (currentLength > 0) {
160 callback(startIndex, text.length, currentLength); 160 callback(startIndex, text.length, currentLength);
161 } 161 }
162 } 162 }
163 } 163 }
OLDNEW
« no previous file with comments | « samples/swarm/swarm_ui_lib/view/CompositeView.dart ('k') | samples/swarm/swarm_ui_lib/view/view.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698