experimental draft, please ignore
git-svn-id: http://skia.googlecode.com/svn/trunk@499 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
c83d422b63
commit
ed8dbf74a7
50
include/text/SkTextLayout.h
Normal file
50
include/text/SkTextLayout.h
Normal file
@ -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<char> fText;
|
||||
SkTextStyle* fDefaultStyle;
|
||||
SkRect fBounds;
|
||||
|
||||
// cache
|
||||
struct Line;
|
||||
struct GlyphRun;
|
||||
SkTDArray<Line*> fLines;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
72
src/text/SkTextLayout.cpp
Normal file
72
src/text/SkTextLayout.cpp
Normal file
@ -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<GlyphRun*> fRuns;
|
||||
};
|
||||
|
||||
SkTextLayout::Line::~Line() {
|
||||
fRuns.deleteAll();
|
||||
}
|
||||
|
||||
void SkTextLayout::draw(SkCanvas* canvas) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user