OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 import 'dart:sky' as sky; |
| 6 |
| 7 void drawText(sky.Canvas canvas, String lh) { |
| 8 sky.Paint paint = new sky.Paint(); |
| 9 |
| 10 // offset down |
| 11 canvas.translate(0.0, 100.0); |
| 12 |
| 13 // set up the text |
| 14 sky.Document document = new sky.Document(); |
| 15 sky.Text arabic = document.createText("مرحبا"); |
| 16 sky.Text english = document.createText(" Hello"); |
| 17 sky.Element block = document.createElement('div'); |
| 18 block.style['display'] = 'paragraph'; |
| 19 block.style['font-family'] = 'serif'; |
| 20 block.style['font-size'] = '50px'; |
| 21 block.style['line-height'] = lh; |
| 22 block.style['color'] = '#0000A0'; |
| 23 block.appendChild(arabic); |
| 24 block.appendChild(english); |
| 25 sky.LayoutRoot layoutRoot = new sky.LayoutRoot(); |
| 26 layoutRoot.rootElement = block; |
| 27 layoutRoot.maxWidth = sky.view.width - 20.0; // you need to set a width for th
is to paint |
| 28 layoutRoot.layout(); |
| 29 |
| 30 // draw a line at the text's baseline |
| 31 sky.Path path = new sky.Path(); |
| 32 path.moveTo(0.0, 0.0); |
| 33 path.lineTo(block.maxContentWidth, 0.0); |
| 34 path.moveTo(0.0, block.alphabeticBaseline); |
| 35 path.lineTo(block.maxContentWidth, block.alphabeticBaseline); |
| 36 path.moveTo(0.0, block.height); |
| 37 path.lineTo(block.maxContentWidth, block.height); |
| 38 paint.color = const sky.Color(0xFFFF9000); |
| 39 paint.setStyle(sky.PaintingStyle.stroke); |
| 40 paint.strokeWidth = 3.0; |
| 41 canvas.drawPath(path, paint); |
| 42 |
| 43 // paint the text |
| 44 layoutRoot.paint(canvas); |
| 45 } |
| 46 |
| 47 void main() { |
| 48 // prepare the rendering |
| 49 sky.PictureRecorder canvas = new sky.PictureRecorder(sky.view.width, sky.view.
height); |
| 50 |
| 51 // background |
| 52 sky.Paint paint = new sky.Paint(); |
| 53 paint.color = const sky.Color(0xFFFFFFFF); |
| 54 paint.setStyle(sky.PaintingStyle.fill); |
| 55 canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, sky.view.width, sky.view.heigh
t), paint); |
| 56 |
| 57 canvas.translate(10.0, 0.0); |
| 58 drawText(canvas, '1.0'); |
| 59 drawText(canvas, 'lh'); |
| 60 |
| 61 // put it on the screen |
| 62 sky.view.picture = canvas.endRecording(); |
| 63 sky.view.scheduleFrame(); |
| 64 } |
OLD | NEW |