2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.h"
|
2018-02-08 20:45:51 +00:00
|
|
|
|
2010-05-17 14:50:04 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
|
|
|
#include "SkCanvas.h"
|
2018-02-08 20:45:51 +00:00
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkColorPriv.h"
|
2011-09-28 15:24:00 +00:00
|
|
|
#include "SkColorShader.h"
|
2010-05-17 14:50:04 +00:00
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkGraphics.h"
|
2018-02-08 20:45:51 +00:00
|
|
|
#include "SkOSFile.h"
|
2010-05-17 14:50:04 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
2018-02-08 20:45:51 +00:00
|
|
|
#include "SkShaper.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkTextBlob.h"
|
2010-05-17 14:50:04 +00:00
|
|
|
#include "SkTime.h"
|
|
|
|
#include "SkTypeface.h"
|
2018-08-21 15:45:46 +00:00
|
|
|
#include "SkUTF.h"
|
2010-05-17 14:50:04 +00:00
|
|
|
|
2011-09-28 15:24:00 +00:00
|
|
|
extern void skia_set_text_gamma(float blackGamma, float whiteGamma);
|
|
|
|
|
2012-08-16 17:35:58 +00:00
|
|
|
#if defined(SK_BUILD_FOR_WIN) && defined(SK_FONTHOST_WIN_GDI)
|
2011-03-01 15:18:14 +00:00
|
|
|
extern SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT&);
|
2011-03-02 14:34:11 +00:00
|
|
|
#endif
|
2011-03-01 15:18:14 +00:00
|
|
|
|
2011-03-02 14:34:11 +00:00
|
|
|
static const char gText[] =
|
2012-08-23 18:19:56 +00:00
|
|
|
"When in the Course of human events it becomes necessary for one people "
|
|
|
|
"to dissolve the political bands which have connected them with another "
|
|
|
|
"and to assume among the powers of the earth, the separate and equal "
|
|
|
|
"station to which the Laws of Nature and of Nature's God entitle them, "
|
|
|
|
"a decent respect to the opinions of mankind requires that they should "
|
|
|
|
"declare the causes which impel them to the separation.";
|
2010-05-17 14:50:04 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class TextBoxView : public Sample {
|
2011-03-02 14:34:11 +00:00
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
TextBoxView() {
|
2012-08-16 17:35:58 +00:00
|
|
|
#if defined(SK_BUILD_FOR_WIN) && defined(SK_FONTHOST_WIN_GDI)
|
2012-08-23 18:19:56 +00:00
|
|
|
LOGFONT lf;
|
|
|
|
sk_bzero(&lf, sizeof(lf));
|
|
|
|
lf.lfHeight = 9;
|
|
|
|
SkTypeface* tf0 = SkCreateTypefaceFromLOGFONT(lf);
|
|
|
|
lf.lfHeight = 12;
|
|
|
|
SkTypeface* tf1 = SkCreateTypefaceFromLOGFONT(lf);
|
|
|
|
// we assert that different sizes should not affect which face we get
|
|
|
|
SkASSERT(tf0 == tf1);
|
|
|
|
tf0->unref();
|
|
|
|
tf1->unref();
|
2011-03-02 14:34:11 +00:00
|
|
|
#endif
|
2011-09-28 15:24:00 +00:00
|
|
|
}
|
2011-03-02 14:34:11 +00:00
|
|
|
|
2010-05-17 14:50:04 +00:00
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
bool onQuery(Sample::Event* evt) override {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "TextBox");
|
2010-05-17 14:50:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
2011-03-02 14:34:11 +00:00
|
|
|
|
2011-09-28 15:24:00 +00:00
|
|
|
void drawTest(SkCanvas* canvas, SkScalar w, SkScalar h, SkColor fg, SkColor bg) {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
|
|
|
canvas->clipRect(SkRect::MakeWH(w, h));
|
|
|
|
canvas->drawColor(bg);
|
2018-02-08 20:45:51 +00:00
|
|
|
|
|
|
|
SkShaper shaper(nullptr);
|
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
SkScalar margin = 20;
|
2010-05-17 14:50:04 +00:00
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2011-04-14 17:53:24 +00:00
|
|
|
paint.setLCDRenderText(true);
|
2011-09-28 15:24:00 +00:00
|
|
|
paint.setColor(fg);
|
2010-05-17 14:50:04 +00:00
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
for (int i = 9; i < 24; i += 2) {
|
2018-02-08 20:45:51 +00:00
|
|
|
SkTextBlobBuilder builder;
|
2012-08-23 18:19:56 +00:00
|
|
|
paint.setTextSize(SkIntToScalar(i));
|
2018-02-08 20:45:51 +00:00
|
|
|
SkPoint end = shaper.shape(&builder, paint, gText, strlen(gText), true,
|
|
|
|
{ margin, margin }, w - margin);
|
|
|
|
canvas->drawTextBlob(builder.make(), 0, 0, paint);
|
|
|
|
|
|
|
|
canvas->translate(0, end.y());
|
2012-08-23 18:19:56 +00:00
|
|
|
}
|
2010-05-17 14:50:04 +00:00
|
|
|
}
|
2011-03-02 14:34:11 +00:00
|
|
|
|
2018-02-08 20:45:51 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2011-09-28 15:24:00 +00:00
|
|
|
SkScalar width = this->width() / 3;
|
|
|
|
drawTest(canvas, width, this->height(), SK_ColorBLACK, SK_ColorWHITE);
|
|
|
|
canvas->translate(width, 0);
|
|
|
|
drawTest(canvas, width, this->height(), SK_ColorWHITE, SK_ColorBLACK);
|
|
|
|
canvas->translate(width, 0);
|
|
|
|
drawTest(canvas, width, this->height()/2, SK_ColorGRAY, SK_ColorWHITE);
|
|
|
|
canvas->translate(0, this->height()/2);
|
|
|
|
drawTest(canvas, width, this->height()/2, SK_ColorGRAY, SK_ColorBLACK);
|
|
|
|
}
|
|
|
|
|
2010-05-17 14:50:04 +00:00
|
|
|
private:
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2010-05-17 14:50:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new TextBoxView(); )
|