Unverified Commit e1174eb0 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

TextPainter RTL (#12791)

parent 19227a99
This diff is collapsed.
......@@ -22,9 +22,9 @@ ui.Picture paint(ui.Rect paintBounds) {
canvas.drawRect(new ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
new ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));
// The paint method of Pargraph draws the contents of the paragraph unto the
// The paint method of Paragraph draws the contents of the paragraph onto the
// given canvas.
canvas.drawParagraph(paragraph, new ui.Offset(paragraph.width / -2.0, (paragraph.width / 2.0) - 125));
canvas.drawParagraph(paragraph, new ui.Offset(-paragraph.width / 2.0, (paragraph.width / 2.0) - 125.0));
return recorder.endRecording();
}
......
......@@ -1013,7 +1013,7 @@ class MessageProperty extends DiagnosticsProperty<Null> {
///
/// The [name], `message`, and [level] arguments must not be null.
MessageProperty(String name, String message, {
DiagnosticLevel level : DiagnosticLevel.info,
DiagnosticLevel level: DiagnosticLevel.info,
}) : assert(name != null),
assert(message != null),
assert(level != null),
......@@ -1032,11 +1032,12 @@ class StringProperty extends DiagnosticsProperty<String> {
/// The [showName], [quoted], and [level] arguments must not be null.
StringProperty(String name, String value, {
String description,
String tooltip,
bool showName: true,
Object defaultValue: kNoDefaultValue,
this.quoted: true,
String ifEmpty,
DiagnosticLevel level : DiagnosticLevel. info,
DiagnosticLevel level: DiagnosticLevel.info,
}) : assert(showName != null),
assert(quoted != null),
assert(level != null),
......@@ -1045,12 +1046,13 @@ class StringProperty extends DiagnosticsProperty<String> {
value,
description: description,
defaultValue: defaultValue,
tooltip: tooltip,
showName: showName,
ifEmpty: ifEmpty,
level: level,
);
/// Whether the description is enclosed in double quotes.
/// Whether the value is enclosed in double quotes.
final bool quoted;
@override
......@@ -1144,7 +1146,7 @@ class DoubleProperty extends _NumProperty<double> {
String unit,
String tooltip,
Object defaultValue: kNoDefaultValue,
bool showName : true,
bool showName: true,
DiagnosticLevel level: DiagnosticLevel.info,
}) : assert(showName != null),
assert(level != null),
......
......@@ -28,11 +28,14 @@ export 'dart:ui' show
Size,
StrokeCap,
StrokeJoin,
TextAffinity,
TextAlign,
TextBaseline,
TextBox,
TextDecoration,
TextDecorationStyle,
TextDirection,
TextPosition,
TileMode,
VertexMode,
VoidCallback,
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphConstraints, ParagraphStyle, TextBox;
import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphConstraints, ParagraphStyle;
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
......@@ -11,6 +11,8 @@ import 'package:flutter/services.dart';
import 'basic_types.dart';
import 'text_span.dart';
export 'package:flutter/services.dart' show TextRange, TextSelection;
final String _kZeroWidthSpace = new String.fromCharCode(0x200B);
/// An object that paints a [TextSpan] tree into a [Canvas].
......@@ -289,13 +291,13 @@ class TextPainter {
/// Valid only after [layout] has been called.
double computeDistanceToActualBaseline(TextBaseline baseline) {
assert(!_needsLayout);
assert(baseline != null);
switch (baseline) {
case TextBaseline.alphabetic:
return _paragraph.alphabeticBaseline;
case TextBaseline.ideographic:
return _paragraph.ideographicBaseline;
}
assert(baseline != null);
return null;
}
......@@ -381,10 +383,10 @@ class TextPainter {
if (prevCodeUnit == null)
return null;
final int prevRuneOffset = _isUtf16Surrogate(prevCodeUnit) ? offset - 2 : offset - 1;
final List<ui.TextBox> boxes = _paragraph.getBoxesForRange(prevRuneOffset, offset);
final List<TextBox> boxes = _paragraph.getBoxesForRange(prevRuneOffset, offset);
if (boxes.isEmpty)
return null;
final ui.TextBox box = boxes[0];
final TextBox box = boxes[0];
final double caretEnd = box.end;
final double dx = box.direction == TextDirection.rtl ? caretEnd : caretEnd - caretPrototype.width;
return new Offset(dx, box.top);
......@@ -395,10 +397,10 @@ class TextPainter {
if (nextCodeUnit == null)
return null;
final int nextRuneOffset = _isUtf16Surrogate(nextCodeUnit) ? offset + 2 : offset + 1;
final List<ui.TextBox> boxes = _paragraph.getBoxesForRange(offset, nextRuneOffset);
final List<TextBox> boxes = _paragraph.getBoxesForRange(offset, nextRuneOffset);
if (boxes.isEmpty)
return null;
final ui.TextBox box = boxes[0];
final TextBox box = boxes[0];
final double caretStart = box.start;
final double dx = box.direction == TextDirection.rtl ? caretStart - caretPrototype.width : caretStart;
return new Offset(dx, box.top);
......@@ -443,6 +445,7 @@ class TextPainter {
Offset getOffsetForCaret(TextPosition position, Rect caretPrototype) {
assert(!_needsLayout);
final int offset = position.offset;
assert(position.affinity != null);
switch (position.affinity) {
case TextAffinity.upstream:
return _getOffsetFromUpstream(offset, caretPrototype)
......@@ -453,7 +456,6 @@ class TextPainter {
?? _getOffsetFromUpstream(offset, caretPrototype)
?? _emptyOffset;
}
assert(position.affinity != null);
return null;
}
......@@ -462,7 +464,7 @@ class TextPainter {
/// A given selection might have more than one rect if this text painter
/// contains bidirectional text because logically contiguous text might not be
/// visually contiguous.
List<ui.TextBox> getBoxesForSelection(TextSelection selection) {
List<TextBox> getBoxesForSelection(TextSelection selection) {
assert(!_needsLayout);
return _paragraph.getBoxesForRange(selection.start, selection.end);
}
......
......@@ -681,8 +681,8 @@ class TextStyle extends Diagnosticable {
defaultValue: null,
));
styles.add(new EnumProperty<FontStyle>('${prefix}style', fontStyle, defaultValue: null));
styles.add(new DoubleProperty('${prefix}letterSpacing', letterSpacing, unit: 'x', defaultValue: null));
styles.add(new DoubleProperty('${prefix}wordSpacing', wordSpacing, unit: 'x', defaultValue: null));
styles.add(new DoubleProperty('${prefix}letterSpacing', letterSpacing, defaultValue: null));
styles.add(new DoubleProperty('${prefix}wordSpacing', wordSpacing, defaultValue: null));
styles.add(new EnumProperty<TextBaseline>('${prefix}baseline', textBaseline, defaultValue: null));
styles.add(new DoubleProperty('${prefix}height', height, unit: 'x', defaultValue: null));
if (decoration != null || decorationColor != null || decorationStyle != null) {
......
......@@ -362,6 +362,11 @@ class RenderEditable extends RenderBox {
/// and the returned list is of length two. In this case, however, the two
/// points might actually be co-located (e.g., because of a bidirectional
/// selection that contains some text but whose ends meet in the middle).
///
/// See also:
///
/// * [getLocalRectForCaret], which is the equivalent but for
/// a [TextPosition] rather than a [TextSelection].
List<TextSelectionPoint> getEndpointsForSelection(TextSelection selection) {
assert(constraints != null);
_layoutText(constraints.maxWidth);
......@@ -385,14 +390,30 @@ class RenderEditable extends RenderBox {
}
/// Returns the position in the text for the given global coordinate.
///
/// See also:
///
/// * [getLocalRectForCaret], which is the reverse operation, taking
/// a [TextPosition] and returning a [Rect].
/// * [TextPainter.getPositionForOffset], which is the equivalent method
/// for a [TextPainter] object.
TextPosition getPositionForPoint(Offset globalPosition) {
_layoutText(constraints.maxWidth);
globalPosition += -_paintOffset;
return _textPainter.getPositionForOffset(globalToLocal(globalPosition));
}
/// Returns the Rect in local coordinates for the caret at the given text
/// Returns the [Rect] in local coordinates for the caret at the given text
/// position.
///
/// See also:
///
/// * [getPositionForPoint], which is the reverse operation, taking
/// an [Offset] in global coordinates and returning a [TextPosition].
/// * [getEndpointsForSelection], which is the equivalent but for
/// a selection rather than a particular text position.
/// * [TextPainter.getOffsetForCaret], the equivalent method for a
/// [TextPainter] object.
Rect getLocalRectForCaret(TextPosition caretPosition) {
_layoutText(constraints.maxWidth);
final Offset caretOffset = _textPainter.getOffsetForCaret(caretPosition, _caretPrototype);
......
This diff is collapsed.
......@@ -134,9 +134,10 @@ Future<Null> benchmarkWidgets(WidgetTesterCallback callback) {
/// that have not yet resolved.
void expect(dynamic actual, dynamic matcher, {
String reason,
dynamic skip, // true or a String
}) {
TestAsyncUtils.guardSync();
test_package.expect(actual, matcher, reason: reason);
test_package.expect(actual, matcher, reason: reason, skip: skip);
}
/// Assert that `actual` matches `matcher`.
......
......@@ -496,6 +496,7 @@ void main() {
'--non-interactive',
'--enable-checked-mode',
'--use-test-fonts',
// '--enable-txt', // enable this to test libtxt rendering
'--packages=$packages',
testPath,
]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment