Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
e1174eb0
Unverified
Commit
e1174eb0
authored
Oct 31, 2017
by
Ian Hickson
Committed by
GitHub
Oct 31, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TextPainter RTL (#12791)
parent
19227a99
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
1822 additions
and
18 deletions
+1822
-18
text.dart
dev/manual_tests/lib/text.dart
+1112
-0
text.dart
examples/layers/raw/text.dart
+2
-2
diagnostics.dart
packages/flutter/lib/src/foundation/diagnostics.dart
+6
-4
basic_types.dart
packages/flutter/lib/src/painting/basic_types.dart
+3
-0
text_painter.dart
packages/flutter/lib/src/painting/text_painter.dart
+10
-8
text_style.dart
packages/flutter/lib/src/painting/text_style.dart
+2
-2
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+22
-1
rrect_test.dart
packages/flutter/test/engine/rrect_test.dart
+0
-0
text_painter_rtl_test.dart
packages/flutter/test/painting/text_painter_rtl_test.dart
+662
-0
widget_tester.dart
packages/flutter_test/lib/src/widget_tester.dart
+2
-1
flutter_platform.dart
packages/flutter_tools/lib/src/test/flutter_platform.dart
+1
-0
No files found.
dev/manual_tests/lib/text.dart
0 → 100644
View file @
e1174eb0
This diff is collapsed.
Click to expand it.
examples/layers/raw/text.dart
View file @
e1174eb0
...
...
@@ -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 Par
graph draws the contents of the paragraph u
nto the
// The paint method of Par
agraph draws the contents of the paragraph o
nto 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
();
}
...
...
packages/flutter/lib/src/foundation/diagnostics.dart
View file @
e1174eb0
...
...
@@ -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
),
...
...
packages/flutter/lib/src/painting/basic_types.dart
View file @
e1174eb0
...
...
@@ -28,11 +28,14 @@ export 'dart:ui' show
Size
,
StrokeCap
,
StrokeJoin
,
TextAffinity
,
TextAlign
,
TextBaseline
,
TextBox
,
TextDecoration
,
TextDecorationStyle
,
TextDirection
,
TextPosition
,
TileMode
,
VertexMode
,
VoidCallback
,
...
...
packages/flutter/lib/src/painting/text_painter.dart
View file @
e1174eb0
...
...
@@ -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
);
}
...
...
packages/flutter/lib/src/painting/text_style.dart
View file @
e1174eb0
...
...
@@ -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
)
{
...
...
packages/flutter/lib/src/rendering/editable.dart
View file @
e1174eb0
...
...
@@ -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
);
...
...
packages/flutter/test/
ui
/rrect_test.dart
→
packages/flutter/test/
engine
/rrect_test.dart
View file @
e1174eb0
File moved
packages/flutter/test/painting/text_painter_rtl_test.dart
0 → 100644
View file @
e1174eb0
This diff is collapsed.
Click to expand it.
packages/flutter_test/lib/src/widget_tester.dart
View file @
e1174eb0
...
...
@@ -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`.
...
...
packages/flutter_tools/lib/src/test/flutter_platform.dart
View file @
e1174eb0
...
...
@@ -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
,
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment