From ed8dbf74a7c8a038ff51d93ad4a174ad6e84663e Mon Sep 17 00:00:00 2001 From: "reed@android.com" Date: Thu, 11 Feb 2010 13:56:04 +0000 Subject: [PATCH] experimental draft, please ignore git-svn-id: http://skia.googlecode.com/svn/trunk@499 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/text/SkTextLayout.h | 50 ++++++++++++++++++++++++++ src/text/SkTextLayout.cpp | 72 +++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 include/text/SkTextLayout.h create mode 100644 src/text/SkTextLayout.cpp diff --git a/include/text/SkTextLayout.h b/include/text/SkTextLayout.h new file mode 100644 index 0000000000..215230708f --- /dev/null +++ b/include/text/SkTextLayout.h @@ -0,0 +1,50 @@ +#ifndef SkTextLayout_DEFINED +#define SkTextLayout_DEFINED + +#include "SkPaint.h" +#include "SkRefCnt.h" + +class SkTextStyle : public SkRefCnt { +public: + SkTextStyle(); + SkTextStyle(const SkTextStyle&); + explicit SkTextStyle(const SkPaint&); + virtual ~SkTextStyle(); + + const SkPaint& paint() const { return fPaint; } + SkPaint& paint() { return fPaint; } + + // todo: bidi-override, language + +private: + SkPaint fPaint; +}; + +class SkTextLayout { +public: + SkTextLayout(); + ~SkTextLayout(); + + void setText(const char text[], size_t length); + void setBounds(const SkRect& bounds); + + SkTextStyle* getDefaultStyle() const { return fDefaultStyle; } + SkTextStyle* setDefaultStyle(SkTextStyle*); + +// SkTextStyle* setStyle(SkTextStyle*, size_t offset, size_t length); + + void draw(SkCanvas* canvas); + +private: + SkTDArray fText; + SkTextStyle* fDefaultStyle; + SkRect fBounds; + + // cache + struct Line; + struct GlyphRun; + SkTDArray fLines; +}; + +#endif + diff --git a/src/text/SkTextLayout.cpp b/src/text/SkTextLayout.cpp new file mode 100644 index 0000000000..09b3acdbdb --- /dev/null +++ b/src/text/SkTextLayout.cpp @@ -0,0 +1,72 @@ +#include "SkTextLayout.h" + +SkTextStyle::SkTextStyle() { + fPaint.setAntiAlias(true); +} + +SkTextStyle::SkTextStyle(const SkTextStyle& src) : fPaint(src.fPaint) {} + +SkTextStyle::SkTextStyle(const SkPaint& paint) : fPaint(paint) {} + +SkTextStyle::~SkTextStyle() {} + +/////////////////////////////////////////////////////////////////////////////// + +SkTextLayout::SkTextLayout() { + fBounds.setEmpty(); + fDefaultStyle = new SkTextStyle; +} + +SkTextLayout::~SkTextLayout() { + fDefaultStyle->unref(); + fLines.deleteAll(); +} + +void SkTextLayout::setText(const char text[], size_t length) { + fText.setCount(length); + memcpy(fText.begin(), text, length); +} + +void SkTextLayout::setBounds(const SkRect& bounds) { + fBounds = bounds; + // if width changed, inval cache +} + +SkTextStyle* SkTextLayout::setDefaultStyle(SkTextStyle* style) { + SkRefCnt_SafeAssign(fDefaultStyle, style); + return style; +} + +/////////////////////////////////////////////////////////////////////////////// + +struct SkTextLayout::GlyphRun { + GlyphRun(); + ~GlyphRun(); + + SkPoint* fLocs; + uint16_t* fGlyphIDs; + int fCount; +}; + +SkTextLayout::GlyphRun::GlyphRun() : fLocs(NULL), fGlyphIDs(NULL), fCount(0) {} + +SkTextLayout::GlyphRun::~GlyphRun() { + delete[] fLocs; + delete[] fGlyphIDs; +} + +struct SkTextLayout::Line { + Line() {} + ~Line(); + + SkScalar fBaselineY; + SkTDArray fRuns; +}; + +SkTextLayout::Line::~Line() { + fRuns.deleteAll(); +} + +void SkTextLayout::draw(SkCanvas* canvas) { +} + -- 2.34.1