SkAtlasTextTarget.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2017 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. #ifndef SkAtlasTextTarget_DEFINED
  8. #define SkAtlasTextTarget_DEFINED
  9. #include "include/core/SkDeque.h"
  10. #include "include/core/SkRefCnt.h"
  11. #include "include/core/SkScalar.h"
  12. #include <memory>
  13. class SkAtlasTextContext;
  14. class SkAtlasTextFont;
  15. class SkMatrix;
  16. struct SkPoint;
  17. /** Represents a client-created renderable surface and is used to draw text into the surface. */
  18. class SK_API SkAtlasTextTarget {
  19. public:
  20. virtual ~SkAtlasTextTarget();
  21. /**
  22. * Creates a text drawing target. ‘handle’ is used to identify this rendering surface when
  23. * draws are flushed to the SkAtlasTextContext's SkAtlasTextRenderer.
  24. */
  25. static std::unique_ptr<SkAtlasTextTarget> Make(sk_sp<SkAtlasTextContext>,
  26. int width,
  27. int height,
  28. void* handle);
  29. /**
  30. * Enqueues a text draw in the target. The caller provides an array of glyphs and their
  31. * positions. The meaning of 'color' here is interpreted by the client's SkAtlasTextRenderer
  32. * when it actually renders the text.
  33. */
  34. virtual void drawText(const SkGlyphID[], const SkPoint[], int glyphCnt, uint32_t color,
  35. const SkAtlasTextFont&) = 0;
  36. /** Issues all queued text draws to SkAtlasTextRenderer. */
  37. virtual void flush() = 0;
  38. int width() const { return fWidth; }
  39. int height() const { return fHeight; }
  40. void* handle() const { return fHandle; }
  41. SkAtlasTextContext* context() const { return fContext.get(); }
  42. /** Saves the current matrix in a stack. Returns the prior depth of the saved matrix stack. */
  43. int save();
  44. /** Pops the top matrix on the stack if the stack is not empty. */
  45. void restore();
  46. /**
  47. * Pops the matrix stack until the stack depth is count. Does nothing if the depth is already
  48. * less than count.
  49. */
  50. void restoreToCount(int count);
  51. /** Pre-translates the current CTM. */
  52. void translate(SkScalar dx, SkScalar dy);
  53. /** Pre-scales the current CTM. */
  54. void scale(SkScalar sx, SkScalar sy);
  55. /** Pre-rotates the current CTM about the origin. */
  56. void rotate(SkScalar degrees);
  57. /** Pre-rotates the current CTM about the (px, py). */
  58. void rotate(SkScalar degrees, SkScalar px, SkScalar py);
  59. /** Pre-skews the current CTM. */
  60. void skew(SkScalar sx, SkScalar sy);
  61. /** Pre-concats the current CTM. */
  62. void concat(const SkMatrix& matrix);
  63. protected:
  64. SkAtlasTextTarget(sk_sp<SkAtlasTextContext>, int width, int height, void* handle);
  65. const SkMatrix& ctm() const { return *static_cast<const SkMatrix*>(fMatrixStack.back()); }
  66. void* const fHandle;
  67. const sk_sp<SkAtlasTextContext> fContext;
  68. const int fWidth;
  69. const int fHeight;
  70. private:
  71. SkDeque fMatrixStack;
  72. int fSaveCnt;
  73. SkMatrix* accessCTM() const {
  74. return static_cast<SkMatrix*>(const_cast<void*>(fMatrixStack.back()));
  75. }
  76. SkAtlasTextTarget() = delete;
  77. SkAtlasTextTarget(const SkAtlasTextContext&) = delete;
  78. SkAtlasTextTarget& operator=(const SkAtlasTextContext&) = delete;
  79. };
  80. #endif