bigtext.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright 2013 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "gm/gm.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkColor.h"
  10. #include "include/core/SkFont.h"
  11. #include "include/core/SkFontTypes.h"
  12. #include "include/core/SkPaint.h"
  13. #include "include/core/SkPoint.h"
  14. #include "include/core/SkRect.h"
  15. #include "include/core/SkSize.h"
  16. #include "include/core/SkString.h"
  17. #include "include/core/SkTypeface.h"
  18. #include "tools/ToolUtils.h"
  19. /**
  20. * Skia may draw from outlines when the size is very large, so we exercise that
  21. * here.
  22. */
  23. class BigTextGM : public skiagm::GM {
  24. public:
  25. BigTextGM() {}
  26. protected:
  27. SkString onShortName() override {
  28. return SkString("bigtext");
  29. }
  30. SkISize onISize() override {
  31. return SkISize::Make(640, 480);
  32. }
  33. void onDraw(SkCanvas* canvas) override {
  34. SkPaint paint;
  35. paint.setAntiAlias(true);
  36. SkFont font(ToolUtils::create_portable_typeface(), 1500);
  37. SkRect r;
  38. (void)font.measureText("/", 1, SkTextEncoding::kUTF8, &r);
  39. SkPoint pos = {
  40. this->width()/2 - r.centerX(),
  41. this->height()/2 - r.centerY()
  42. };
  43. paint.setColor(SK_ColorRED);
  44. canvas->drawSimpleText("/", 1, SkTextEncoding::kUTF8, pos.fX, pos.fY, font, paint);
  45. paint.setColor(SK_ColorBLUE);
  46. canvas->drawSimpleText("\\", 1, SkTextEncoding::kUTF8, pos.fX, pos.fY, font, paint);
  47. }
  48. private:
  49. typedef skiagm::GM INHERITED;
  50. };
  51. DEF_GM(return new BigTextGM;)