|
1 |
|
2 /* |
|
3 * Copyright 2006 The Android Open Source Project |
|
4 * |
|
5 * Use of this source code is governed by a BSD-style license that can be |
|
6 * found in the LICENSE file. |
|
7 */ |
|
8 |
|
9 |
|
10 #include "SkDrawTextBox.h" |
|
11 #include "SkAnimateMaker.h" |
|
12 #include "SkCanvas.h" |
|
13 #include "SkPaint.h" |
|
14 |
|
15 enum SkDrawTextBox_Properties { |
|
16 foo = 100, |
|
17 SK_PROPERTY(spacingAlign), |
|
18 SK_PROPERTY(mode) |
|
19 }; |
|
20 |
|
21 |
|
22 #if SK_USE_CONDENSED_INFO == 0 |
|
23 |
|
24 const SkMemberInfo SkDrawTextBox::fInfo[] = { |
|
25 SK_MEMBER_INHERITED, |
|
26 SK_MEMBER(mode, TextBoxMode), |
|
27 SK_MEMBER_ALIAS(spacingAdd, fSpacingAdd, Float), |
|
28 SK_MEMBER(spacingAlign, TextBoxAlign), |
|
29 SK_MEMBER_ALIAS(spacingMul, fSpacingMul, Float), |
|
30 SK_MEMBER_ALIAS(text, fText, String) |
|
31 }; |
|
32 |
|
33 #endif |
|
34 |
|
35 DEFINE_GET_MEMBER(SkDrawTextBox); |
|
36 |
|
37 SkDrawTextBox::SkDrawTextBox() |
|
38 { |
|
39 fSpacingMul = SK_Scalar1; |
|
40 fSpacingAdd = 0; |
|
41 spacingAlign = SkTextBox::kStart_SpacingAlign; |
|
42 mode = SkTextBox::kLineBreak_Mode; |
|
43 } |
|
44 |
|
45 #ifdef SK_DUMP_ENABLED |
|
46 void SkDrawTextBox::dump(SkAnimateMaker* maker) |
|
47 { |
|
48 dumpBase(maker); |
|
49 dumpAttrs(maker); |
|
50 if (mode == 0) |
|
51 SkDebugf("mode=\"oneLine\" "); |
|
52 if (spacingAlign == 1) |
|
53 SkDebugf("spacingAlign=\"center\" "); |
|
54 else if (spacingAlign == 2) |
|
55 SkDebugf("spacingAlign=\"end\" "); |
|
56 SkDebugf("/>\n"); |
|
57 } |
|
58 #endif |
|
59 |
|
60 bool SkDrawTextBox::getProperty(int index, SkScriptValue* value) const |
|
61 { |
|
62 return this->INHERITED::getProperty(index, value); |
|
63 } |
|
64 |
|
65 bool SkDrawTextBox::setProperty(int index, SkScriptValue& scriptValue) |
|
66 { |
|
67 return this->INHERITED::setProperty(index, scriptValue); |
|
68 } |
|
69 |
|
70 bool SkDrawTextBox::draw(SkAnimateMaker& maker) |
|
71 { |
|
72 SkTextBox box; |
|
73 box.setMode((SkTextBox::Mode) mode); |
|
74 box.setSpacingAlign((SkTextBox::SpacingAlign) spacingAlign); |
|
75 box.setBox(fRect); |
|
76 box.setSpacing(fSpacingMul, fSpacingAdd); |
|
77 SkBoundableAuto boundable(this, maker); |
|
78 box.draw(maker.fCanvas, fText.c_str(), fText.size(), *maker.fPaint); |
|
79 return false; |
|
80 } |