blob: c4be2b89654be05ba9dff9e54b9535fcb7b97414 [file] [log] [blame]
reed@android.comc07d23a2009-02-06 13:30:58 +00001#include "SampleCode.h"
2#include "SkView.h"
3#include "SkCanvas.h"
4#include "SkGradientShader.h"
5#include "SkGraphics.h"
6#include "SkImageDecoder.h"
7#include "SkPath.h"
8#include "SkPorterDuff.h"
9#include "SkRegion.h"
10#include "SkShader.h"
11#include "SkUtils.h"
12#include "SkXfermode.h"
13#include "SkColorPriv.h"
14#include "SkColorFilter.h"
15#include "SkTime.h"
16#include "SkTypeface.h"
17
reed@android.com54043a32009-03-05 14:14:49 +000018#if 0
19static void CFString2SkString(CFStringRef ref, SkString* str) {
20 str->reset();
21 int count = CFStringGetLength(ref);
22 for (int i = 0; i < count; i++) {
23 SkString tmp;
24 UniChar c = CFStringGetCharacterAtIndex(ref, i);
25 tmp.setUTF16(&c, 1);
26 str->append(tmp);
27 }
28}
29
30static size_t get_table_size(ATSFontRef font, uint32_t tableTag) {
31 ByteCount size;
32 OSStatus status = ATSFontGetTable(font, tableTag, 0, 0, NULL, &size);
33 if (status) {
34 SkDebugf("*** ATSFontGetTable returned %d\n", status);
35 size = -1;
36 }
37 return size;
38}
39
40static void test_ats() {
41 OSStatus status;
42 ATSFontIterator iter;
43 status = ATSFontIteratorCreate(kATSFontContextLocal, NULL, NULL,
44 kATSOptionFlagsUnRestrictedScope, &iter);
45
46 for (int index = 0;; index++) {
47 ATSFontRef fontRef;
48 status = ATSFontIteratorNext(iter, &fontRef);
49 if (status) {
50 break;
51 }
52
53 CFStringRef name;
54 SkString str;
55 ATSFontGetName(fontRef, kATSOptionFlagsDefault, &name);
56 CFString2SkString(name, &str);
57 if (str.size() > 0 && str.c_str()[0] != '.') {
58 SkDebugf("[%3d] font %x cmap %d 'name' %d <%s>\n", index, fontRef,
59 get_table_size(fontRef, 'cmap'),
60 get_table_size(fontRef, 'name'),
61 str.c_str());
62 }
63 CFRelease(name);
64 }
65 ATSFontIteratorRelease(&iter);
66}
67#endif
68
reed@android.comc07d23a2009-02-06 13:30:58 +000069class PathClipView : public SkView {
70public:
71 SkRect fOval;
72 SkPoint fCenter;
73
74 PathClipView() {
75 fOval.set(0, 0, SkIntToScalar(200), SkIntToScalar(50));
76 fCenter.set(SkIntToScalar(250), SkIntToScalar(250));
reed@android.com54043a32009-03-05 14:14:49 +000077
78// test_ats();
reed@android.comc07d23a2009-02-06 13:30:58 +000079 }
80
81 virtual ~PathClipView() {}
82
83protected:
84 // overrides from SkEventSink
85 virtual bool onQuery(SkEvent* evt) {
86 if (SampleCode::TitleQ(*evt)) {
87 SampleCode::TitleR(evt, "PathClip");
88 return true;
89 }
90 return this->INHERITED::onQuery(evt);
91 }
92
93 void drawBG(SkCanvas* canvas) {
94 canvas->drawColor(SK_ColorWHITE);
95 }
96
97 virtual void onDraw(SkCanvas* canvas) {
98 this->drawBG(canvas);
99
100 SkRect oval = fOval;
101 oval.offset(fCenter.fX - oval.centerX(), fCenter.fY - oval.centerY());
102
103 SkPaint p;
104 p.setAntiAlias(true);
105
106 p.setStyle(SkPaint::kStroke_Style);
107 canvas->drawOval(oval, p);
108
109 SkRect r;
110 r.set(SkIntToScalar(200), SkIntToScalar(200),
111 SkIntToScalar(300), SkIntToScalar(300));
112 canvas->clipRect(r);
113
114 p.setStyle(SkPaint::kFill_Style);
115 p.setColor(SK_ColorRED);
116 canvas->drawRect(r, p);
117
118 p.setColor(0x800000FF);
119 r.set(SkIntToScalar(150), SkIntToScalar(10),
120 SkIntToScalar(250), SkIntToScalar(400));
121 canvas->drawOval(oval, p);
122 }
123
124 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
125 fCenter.set(x, y);
126 this->inval(NULL);
127 return NULL;
128 }
129
130private:
131 typedef SkView INHERITED;
132};
133
134//////////////////////////////////////////////////////////////////////////////
135
136static SkView* MyFactory() { return new PathClipView; }
137static SkViewRegister reg(MyFactory);
138