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

Unified Diff: sky/examples/rendering/baseline.dart

Issue 1200233002: Use the baseline information exposed by C++ to pipe baseline data through RenderBox. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/engine/core/rendering/RenderParagraph.cpp ('k') | sky/sdk/lib/rendering/block.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/rendering/baseline.dart
diff --git a/sky/examples/rendering/baseline.dart b/sky/examples/rendering/baseline.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2c52239597d987870f5f552bae8128530659c818
--- /dev/null
+++ b/sky/examples/rendering/baseline.dart
@@ -0,0 +1,78 @@
+// 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 'dart:sky' as sky;
+
+import 'package:sky/painting/text_style.dart';
+import 'package:sky/rendering/block.dart';
+import 'package:sky/rendering/box.dart';
+import 'package:sky/rendering/object.dart';
+import 'package:sky/rendering/paragraph.dart';
+import 'package:sky/rendering/sky_binding.dart';
+
+RenderBox getBox(double lh) {
+ RenderParagraph paragraph = new RenderParagraph(
+ new InlineStyle(
+ new TextStyle(),
+ [
+ new InlineText('test'),
+ new InlineStyle(
+ new TextStyle(
+ color: const Color(0xFF0000A0),
+ fontFamily: 'serif',
+ fontSize: 50.0,
+ height: lh
+ ),
+ [new InlineText('مرحبا Hello')]
+ )
+ ]
+ )
+ );
+ return new RenderPadding(
+ padding: new EdgeDims.all(10.0),
+ child: new RenderConstrainedBox(
+ additionalConstraints: new BoxConstraints.tightFor(height: 200.0),
+ child: new RenderDecoratedBox(
+ decoration: new BoxDecoration(
+ backgroundColor: const Color(0xFFFFFFFF)
+ ),
+ child: new RenderPadding(
+ padding: new EdgeDims.all(10.0),
+ child: new RenderCustomPaint(
+ child: paragraph,
+ callback: (canvas, size) {
+ double baseline = paragraph.getDistanceToBaseline(TextBaseline.alphabetic);
+ double w = paragraph.getMaxIntrinsicWidth(new BoxConstraints.loose(size));
+ double h = paragraph.getMaxIntrinsicHeight(new BoxConstraints.loose(size));
+ Path path = new Path();
+ path.moveTo(0.0, 0.0);
+ path.lineTo(w, 0.0);
+ path.moveTo(0.0, baseline);
+ path.lineTo(w, baseline);
+ path.moveTo(0.0, h);
+ path.lineTo(w, h);
+ Paint paint = new Paint();
+ paint.color = const Color(0xFFFF9000);
+ paint.setStyle(sky.PaintingStyle.stroke);
+ paint.strokeWidth = 3.0;
+ canvas.drawPath(path, paint);
+ }
+ )
+ )
+ )
+ )
+ );
+}
+
+void main() {
+ RenderBox root = new RenderBlock(children: [
+ new RenderConstrainedBox(
+ additionalConstraints: new BoxConstraints.tightFor(height: 50.0)
+ ),
+ getBox(1.0),
+ getBox(null),
+ ]);
+ var b = new SkyBinding(root: root);
+ // b.onFrame = b.debugDumpRenderTree;
+}
« no previous file with comments | « sky/engine/core/rendering/RenderParagraph.cpp ('k') | sky/sdk/lib/rendering/block.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698