TextPainter RTL (#11888)

This commit is contained in:
Ian Hickson
2017-09-07 16:57:38 -07:00
committed by GitHub
parent f4ccb4b6a4
commit ca7d2d23cf
144 changed files with 2223 additions and 1019 deletions

View File

@@ -0,0 +1,7 @@
```
# To run the Hello World demo:
flutter run
# To run the Hello World demo showing Arabic:
flutter run lib/arabic.dart
```

View File

@@ -0,0 +1,7 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/widgets.dart';
void main() => runApp(const Center(child: const Text('برنامج أهلا بالعالم', textDirection: TextDirection.rtl)));

View File

@@ -4,4 +4,4 @@
import 'package:flutter/widgets.dart';
void main() => runApp(const Center(child: const Text('Hello, world!')));
void main() => runApp(const Center(child: const Text('Hello, world!', textDirection: TextDirection.ltr)));

View File

@@ -4,4 +4,4 @@
import 'package:flutter/widgets.dart';
void main() => runApp(const Center(child: const Text('flutter run -t xxx/yyy.dart')));
void main() => runApp(const Center(child: const Text('flutter run -t xxx/yyy.dart', textDirection: TextDirection.ltr)));

View File

@@ -11,7 +11,9 @@ void beginFrame(Duration timeStamp) {
final double devicePixelRatio = ui.window.devicePixelRatio;
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
final ui.ParagraphBuilder paragraphBuilder = new ui.ParagraphBuilder(new ui.ParagraphStyle())
final ui.ParagraphBuilder paragraphBuilder = new ui.ParagraphBuilder(
new ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
)
..addText('Hello, world.');
final ui.Paragraph paragraph = paragraphBuilder.build()
..layout(new ui.ParagraphConstraints(width: logicalSize.width));

View File

@@ -52,7 +52,13 @@ void beginFrame(Duration timeStamp) {
void main() {
// To create a paragraph of text, we use ParagraphBuilder.
final ui.ParagraphBuilder builder = new ui.ParagraphBuilder(new ui.ParagraphStyle())
final ui.ParagraphBuilder builder = new ui.ParagraphBuilder(
// The text below has a primary direction of left-to-right.
// The embedded text has other directions.
// If this was TextDirection.rtl, the "Hello, world" text would end up on
// the other side of the right-to-left text.
new ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
)
// We first push a style that turns the text blue.
..pushStyle(new ui.TextStyle(color: const ui.Color(0xFF0000FF)))
..addText('Hello, ')

View File

@@ -14,24 +14,36 @@ void main() {
void addAlignmentRow(CrossAxisAlignment crossAxisAlignment) {
TextStyle style = const TextStyle(color: const Color(0xFF000000));
final RenderParagraph paragraph = new RenderParagraph(new TextSpan(style: style, text: '$crossAxisAlignment'));
final RenderParagraph paragraph = new RenderParagraph(
new TextSpan(style: style, text: '$crossAxisAlignment'),
textDirection: TextDirection.ltr,
);
table.add(new RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0)));
final RenderFlex row = new RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic);
style = const TextStyle(fontSize: 15.0, color: const Color(0xFF000000));
row.add(new RenderDecoratedBox(
decoration: const BoxDecoration(color: const Color(0x7FFFCCCC)),
child: new RenderParagraph(new TextSpan(style: style, text: 'foo foo foo'))
child: new RenderParagraph(
new TextSpan(style: style, text: 'foo foo foo'),
textDirection: TextDirection.ltr,
),
));
style = const TextStyle(fontSize: 10.0, color: const Color(0xFF000000));
row.add(new RenderDecoratedBox(
decoration: const BoxDecoration(color: const Color(0x7FCCFFCC)),
child: new RenderParagraph(new TextSpan(style: style, text: 'foo foo foo'))
child: new RenderParagraph(
new TextSpan(style: style, text: 'foo foo foo'),
textDirection: TextDirection.ltr,
),
));
final RenderFlex subrow = new RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic);
style = const TextStyle(fontSize: 25.0, color: const Color(0xFF000000));
subrow.add(new RenderDecoratedBox(
decoration: const BoxDecoration(color: const Color(0x7FCCCCFF)),
child: new RenderParagraph(new TextSpan(style: style, text: 'foo foo foo foo'))
child: new RenderParagraph(
new TextSpan(style: style, text: 'foo foo foo foo'),
textDirection: TextDirection.ltr,
),
));
subrow.add(new RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: const Size(30.0, 40.0)));
row.add(subrow);
@@ -48,7 +60,10 @@ void main() {
void addJustificationRow(MainAxisAlignment justify) {
const TextStyle style = const TextStyle(color: const Color(0xFF000000));
final RenderParagraph paragraph = new RenderParagraph(new TextSpan(style: style, text: '$justify'));
final RenderParagraph paragraph = new RenderParagraph(
new TextSpan(style: style, text: '$justify'),
textDirection: TextDirection.ltr,
);
table.add(new RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0)));
final RenderFlex row = new RenderFlex(direction: Axis.horizontal);
row.add(new RenderSolidColorBox(const Color(0xFFFFCCCC), desiredSize: const Size(80.0, 60.0)));

View File

@@ -16,7 +16,14 @@ void main() {
alignment: FractionalOffset.center,
// We use a RenderParagraph to display the text 'Hello, world.' without
// any explicit styling.
child: new RenderParagraph(const TextSpan(text: 'Hello, world.'))
child: new RenderParagraph(
const TextSpan(text: 'Hello, world.'),
// The text is in English so we specify the text direction as
// left-to-right. If the text had been in Hebrew or Arabic, we would
// have specified right-to-left. The Flutter framework does not assume a
// particular text direction.
textDirection: TextDirection.ltr,
),
)
);
}

View File

@@ -104,8 +104,9 @@ void main() {
final RenderParagraph paragraph = new RenderParagraph(
const TextSpan(
style: const TextStyle(color: Colors.black87),
text: "Touch me!"
)
text: "Touch me!",
),
textDirection: TextDirection.ltr,
);
// A stack is a render object that layers its children on top of each other.
// The bottom later is our RenderDots object, and on top of that we show the
@@ -114,7 +115,7 @@ void main() {
children: <RenderBox>[
new RenderDots(),
paragraph,
]
],
);
// The "parentData" field of a render object is controlled by the render
// object's parent render object. Now that we've added the paragraph as a

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../lib/main.dart' as demo;
void main() {
test('layers smoketest for lib/main.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../raw/canvas.dart' as demo;
void main() {
test('layers smoketest for raw/canvas.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../raw/hello_world.dart' as demo;
void main() {
test('layers smoketest for raw/hello_world.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../raw/spinning_square.dart' as demo;
void main() {
test('layers smoketest for raw/spinning_square.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../raw/text.dart' as demo;
void main() {
test('layers smoketest for raw/text.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../raw/touch_input.dart' as demo;
void main() {
test('layers smoketest for raw/touch_input.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../rendering/custom_coordinate_systems.dart' as demo;
void main() {
test('layers smoketest for rendering/custom_coordinate_systems.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../rendering/flex_layout.dart' as demo;
void main() {
test('layers smoketest for rendering/flex_layout.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../rendering/hello_world.dart' as demo;
void main() {
test('layers smoketest for rendering/hello_world.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../rendering/spinning_square.dart' as demo;
void main() {
test('layers smoketest for rendering/spinning_square.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../rendering/touch_input.dart' as demo;
void main() {
test('layers smoketest for rendering/touch_input.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../services/isolate.dart' as demo;
void main() {
test('layers smoketest for services/isolate.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../services/lifecycle.dart' as demo;
void main() {
test('layers smoketest for services/lifecycle.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../widgets/custom_render_box.dart' as demo;
void main() {
test('layers smoketest for widgets/custom_render_box.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../widgets/gestures.dart' as demo;
void main() {
test('layers smoketest for widgets/gestures.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../widgets/hello_world.dart' as demo;
void main() {
test('layers smoketest for widgets/hello_world.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../widgets/media_query.dart' as demo;
void main() {
test('layers smoketest for widgets/media_query.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../widgets/sectors.dart' as demo;
void main() {
test('layers smoketest for widgets/sectors.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../widgets/spinning_mixed.dart' as demo;
void main() {
test('layers smoketest for widgets/spinning_mixed.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../widgets/spinning_square.dart' as demo;
void main() {
test('layers smoketest for widgets/spinning_square.dart', () {
demo.main();
});
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import '../../../widgets/styled_text.dart' as demo;
void main() {
test('layers smoketest for widgets/styled_text.dart', () {
demo.main();
});
}

View File

@@ -4,4 +4,4 @@
import 'package:flutter/widgets.dart';
void main() => runApp(const Center(child: const Text('Hello, world!')));
void main() => runApp(const Center(child: const Text('Hello, world!', textDirection: TextDirection.ltr)));

View File

@@ -37,40 +37,43 @@ BuildOwner owner = new BuildOwner();
void attachWidgetTreeToRenderTree(RenderProxyBox container) {
element = new RenderObjectToWidgetAdapter<RenderBox>(
container: container,
child: new Container(
height: 300.0,
child: new Column(
children: <Widget>[
const Rectangle(const Color(0xFF00FFFF)),
new Material(
child: new Container(
padding: const EdgeInsets.all(10.0),
margin: const EdgeInsets.all(10.0),
child: new Row(
children: <Widget>[
new RaisedButton(
child: new Row(
children: <Widget>[
new Image.network('https://flutter.io/images/favicon.png'),
const Text('PRESS ME'),
]
child: new Directionality(
textDirection: TextDirection.ltr,
child: new Container(
height: 300.0,
child: new Column(
children: <Widget>[
const Rectangle(const Color(0xFF00FFFF)),
new Material(
child: new Container(
padding: const EdgeInsets.all(10.0),
margin: const EdgeInsets.all(10.0),
child: new Row(
children: <Widget>[
new RaisedButton(
child: new Row(
children: <Widget>[
new Image.network('https://flutter.io/images/favicon.png'),
const Text('PRESS ME'),
],
),
onPressed: () {
value = value == null ? 0.1 : (value + 0.1) % 1.0;
attachWidgetTreeToRenderTree(container);
},
),
onPressed: () {
value = value == null ? 0.1 : (value + 0.1) % 1.0;
attachWidgetTreeToRenderTree(container);
}
),
new CircularProgressIndicator(value: value),
],
mainAxisAlignment: MainAxisAlignment.spaceAround
)
)
),
const Rectangle(const Color(0xFFFFFF00)),
],
mainAxisAlignment: MainAxisAlignment.spaceBetween
)
)
new CircularProgressIndicator(value: value),
],
mainAxisAlignment: MainAxisAlignment.spaceAround,
),
),
),
const Rectangle(const Color(0xFFFFFF00)),
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,
),
),
),
).attachToRenderTree(owner, element);
}