|
1 |
|
2 /* |
|
3 * Copyright 2011 Google Inc. |
|
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 #include "SkTextLayout.h" |
|
9 |
|
10 SkTextStyle::SkTextStyle() { |
|
11 fPaint.setAntiAlias(true); |
|
12 } |
|
13 |
|
14 SkTextStyle::SkTextStyle(const SkTextStyle& src) : fPaint(src.fPaint) {} |
|
15 |
|
16 SkTextStyle::SkTextStyle(const SkPaint& paint) : fPaint(paint) {} |
|
17 |
|
18 SkTextStyle::~SkTextStyle() {} |
|
19 |
|
20 /////////////////////////////////////////////////////////////////////////////// |
|
21 |
|
22 SkTextLayout::SkTextLayout() { |
|
23 fBounds.setEmpty(); |
|
24 fDefaultStyle = new SkTextStyle; |
|
25 } |
|
26 |
|
27 SkTextLayout::~SkTextLayout() { |
|
28 fDefaultStyle->unref(); |
|
29 fLines.deleteAll(); |
|
30 } |
|
31 |
|
32 void SkTextLayout::setText(const char text[], size_t length) { |
|
33 fText.setCount(length); |
|
34 memcpy(fText.begin(), text, length); |
|
35 } |
|
36 |
|
37 void SkTextLayout::setBounds(const SkRect& bounds) { |
|
38 fBounds = bounds; |
|
39 // if width changed, inval cache |
|
40 } |
|
41 |
|
42 SkTextStyle* SkTextLayout::setDefaultStyle(SkTextStyle* style) { |
|
43 SkRefCnt_SafeAssign(fDefaultStyle, style); |
|
44 return style; |
|
45 } |
|
46 |
|
47 /////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
49 struct SkTextLayout::GlyphRun { |
|
50 GlyphRun(); |
|
51 ~GlyphRun(); |
|
52 |
|
53 SkPoint* fLocs; |
|
54 uint16_t* fGlyphIDs; |
|
55 int fCount; |
|
56 }; |
|
57 |
|
58 SkTextLayout::GlyphRun::GlyphRun() : fLocs(NULL), fGlyphIDs(NULL), fCount(0) {} |
|
59 |
|
60 SkTextLayout::GlyphRun::~GlyphRun() { |
|
61 delete[] fLocs; |
|
62 delete[] fGlyphIDs; |
|
63 } |
|
64 |
|
65 struct SkTextLayout::Line { |
|
66 Line() {} |
|
67 ~Line(); |
|
68 |
|
69 SkScalar fBaselineY; |
|
70 SkTDArray<GlyphRun*> fRuns; |
|
71 }; |
|
72 |
|
73 SkTextLayout::Line::~Line() { |
|
74 fRuns.deleteAll(); |
|
75 } |
|
76 |
|
77 void SkTextLayout::draw(SkCanvas* canvas) { |
|
78 } |