diff options
| author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-03-09 18:12:13 +0000 |
|---|---|---|
| committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-03-09 18:12:13 +0000 |
| commit | 330578d67d466f97c47aecdbdda9d69aa2aa7569 (patch) | |
| tree | 8355584e5f1b7ad000358c6e2be20db4bedc9cc9 /samplecode/SampleFontScalerTest.cpp | |
| parent | 0bf64d48cc18d551dadc7cce0c990352e04f9af8 (diff) | |
mac fonts sort of work now
- haven't tested rotation yet
- spacing/bounds still look bad
git-svn-id: http://skia.googlecode.com/svn/trunk@117 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'samplecode/SampleFontScalerTest.cpp')
| -rw-r--r-- | samplecode/SampleFontScalerTest.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/samplecode/SampleFontScalerTest.cpp b/samplecode/SampleFontScalerTest.cpp new file mode 100644 index 0000000000..380d34671a --- /dev/null +++ b/samplecode/SampleFontScalerTest.cpp @@ -0,0 +1,91 @@ +#include "SampleCode.h" +#include "SkView.h" +#include "SkCanvas.h" +#include "SkTypeface.h" +#include "SkPath.h" +#include "SkRegion.h" +#include "SkShader.h" +#include "SkUtils.h" +#include "Sk1DPathEffect.h" +#include "SkCornerPathEffect.h" +#include "SkPathMeasure.h" +#include "SkRandom.h" +#include "SkColorPriv.h" +#include "SkColorFilter.h" +#include "SkDither.h" + +static const struct { + const char* fName; + SkTypeface::Style fStyle; +} gFaces[] = { + { NULL, SkTypeface::kNormal }, + { NULL, SkTypeface::kBold }, + { "serif", SkTypeface::kNormal }, + { "serif", SkTypeface::kBold }, + { "serif", SkTypeface::kItalic }, + { "serif", SkTypeface::kBoldItalic }, + { "monospace", SkTypeface::kNormal } +}; + +static const int gFaceCount = SK_ARRAY_COUNT(gFaces); + +class FontScalerTestView : public SkView { + SkTypeface* fFaces[gFaceCount]; + +public: + FontScalerTestView() { + for (int i = 0; i < gFaceCount; i++) { + fFaces[i] = SkTypeface::CreateFromName(gFaces[i].fName, + gFaces[i].fStyle); + } + } + + virtual ~FontScalerTestView() { + for (int i = 0; i < gFaceCount; i++) { + fFaces[i]->safeUnref(); + } + } + +protected: + // overrides from SkEventSink + virtual bool onQuery(SkEvent* evt) { + if (SampleCode::TitleQ(*evt)) { + SampleCode::TitleR(evt, "FontScaler Test"); + return true; + } + return this->INHERITED::onQuery(evt); + } + + void drawBG(SkCanvas* canvas) { + canvas->drawColor(0xFFDDDDDD); + } + + virtual void onDraw(SkCanvas* canvas) { + this->drawBG(canvas); + + SkPaint paint; + paint.setAntiAlias(true); + paint.setTypeface(SkTypeface::CreateFromName("Times Roman", SkTypeface::kNormal))->safeUnref(); + + const char* text = "HHHaaammmbbbuuurrrgggeeefffooonnnsss"; + const size_t textLen = strlen(text); + + SkScalar x = SkIntToScalar(10); + SkScalar y = SkIntToScalar(20); + + for (int ps = 9; ps <= 24; ps++) { + paint.setTextSize(SkIntToScalar(ps)); + canvas->drawText(text, textLen, x, y, paint); + y += paint.getFontMetrics(NULL); + } + } + +private: + typedef SkView INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +static SkView* MyFactory() { return new FontScalerTestView; } +static SkViewRegister reg(MyFactory); + |
