summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-07 00:44:49 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-07 00:44:49 +0000
commit83f6e08f4c56ef411ad1da5f3bfd4711ec94b052 (patch)
tree6bf8e871963cfc1ab8bf6190dceed5b9631cf8ee /skia
parentd5c0e0e416a67e7e8dd98745cdf1bdc7de20517c (diff)
downloadchromium_src-83f6e08f4c56ef411ad1da5f3bfd4711ec94b052.zip
chromium_src-83f6e08f4c56ef411ad1da5f3bfd4711ec94b052.tar.gz
chromium_src-83f6e08f4c56ef411ad1da5f3bfd4711ec94b052.tar.bz2
Add Harfbuzz to third_party and Skia support for such.
Harfbuzz is an open source library which is a unification of the Qt and Pango shaping engines. We'll be using it on Chromium Linux to perform complex text shaping. Additionally, we add support for Harfbuzz into Skia, guarded by SKIA_HARFBUZZ. http://codereview.chromium.org/63035/show git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13214 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/include/SkPaint.h7
-rw-r--r--skia/include/SkScalerContext.h10
-rw-r--r--skia/ports/SkFontHost_FreeType.cpp65
-rw-r--r--skia/sgl/SkGlyphCache.cpp12
-rw-r--r--skia/sgl/SkGlyphCache.h11
-rw-r--r--skia/sgl/SkPaint.cpp12
-rw-r--r--skia/skia.gyp5
7 files changed, 122 insertions, 0 deletions
diff --git a/skia/include/SkPaint.h b/skia/include/SkPaint.h
index bb386c6..dea8de6 100644
--- a/skia/include/SkPaint.h
+++ b/skia/include/SkPaint.h
@@ -39,6 +39,8 @@ class SkDrawLooper;
class SkTypeface;
class SkXfermode;
+typedef struct HB_ShaperItem_ HB_ShaperItem;
+
typedef const SkGlyph& (*SkDrawCacheProc)(SkGlyphCache*, const char**,
SkFixed x, SkFixed y);
@@ -736,6 +738,11 @@ public:
void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
SkPath* path) const;
+#ifdef SKIA_HARFBUZZ
+ void setupShaper(HB_ShaperItem* item);
+ void releaseShaper(HB_ShaperItem* item);
+#endif
+
private:
SkTypeface* fTypeface;
SkScalar fTextSize;
diff --git a/skia/include/SkScalerContext.h b/skia/include/SkScalerContext.h
index df846f2..1299f1b 100644
--- a/skia/include/SkScalerContext.h
+++ b/skia/include/SkScalerContext.h
@@ -28,6 +28,8 @@ class SkMaskFilter;
class SkPathEffect;
class SkRasterizer;
+typedef struct HB_ShaperItem_ HB_ShaperItem;
+
// needs to be != to any valid SkMask::Format
#define MASK_FORMAT_JUST_ADVANCE (0xFF)
@@ -192,6 +194,14 @@ public:
static inline void MakeRec(const SkPaint&, const SkMatrix*, Rec* rec);
static SkScalerContext* Create(const SkDescriptor*);
+#ifdef SKIA_HARFBUZZ
+ // This will fill in |item->font| and |item->face| with valid values for
+ // this font.
+ virtual void setupShaper(HB_ShaperItem* item) = 0;
+ // This will release the references held by |item->font| and |item->face|.
+ virtual void releaseShaper(HB_ShaperItem* item) = 0;
+#endif
+
protected:
Rec fRec;
unsigned fBaseGlyphCount;
diff --git a/skia/ports/SkFontHost_FreeType.cpp b/skia/ports/SkFontHost_FreeType.cpp
index 78938d6..56ea08d 100644
--- a/skia/ports/SkFontHost_FreeType.cpp
+++ b/skia/ports/SkFontHost_FreeType.cpp
@@ -36,6 +36,13 @@
#include FT_ADVANCES_H
#endif
+#ifdef SKIA_HARFBUZZ
+extern "C" {
+#include <harfbuzz-shaper.h>
+#include <harfbuzz-freetype.h>
+}
+#endif
+
#if 0
// Also include the files by name for build tools which require this.
#include <freetype/freetype.h>
@@ -77,6 +84,11 @@ public:
return fFaceRec != NULL && fFTSize != NULL;
}
+#ifdef SKIA_HARFBUZZ
+ virtual void setupShaper(HB_ShaperItem* item);
+ virtual void releaseShaper(HB_ShaperItem* item);
+#endif
+
protected:
virtual unsigned generateGlyphCount() const;
virtual uint16_t generateCharToGlyph(SkUnichar uni);
@@ -111,8 +123,25 @@ struct SkFaceRec {
uint32_t fRefCnt;
uint32_t fFontID;
+#ifdef SKIA_HARFBUZZ
+ // A lazily created Harfbuzz face object.
+ HB_Face fHBFace;
+ // If |fHBFace| is non-NULL, then this member is valid.
+ HB_FontRec* fHBFont;
+
+ void setupShaper(HB_ShaperItem* item);
+ void releaseShaper(HB_ShaperItem* item);
+#endif
+
SkFaceRec(SkStream* strm, uint32_t fontID);
~SkFaceRec() {
+#ifdef SKIA_HARFBUZZ
+ if (fHBFace) {
+ free(fHBFace);
+ free(fHBFont);
+ }
+#endif
+
fSkStream->unref();
}
};
@@ -157,6 +186,11 @@ SkFaceRec::SkFaceRec(SkStream* strm, uint32_t fontID)
fFTStream.descriptor.pointer = fSkStream;
fFTStream.read = sk_stream_read;
fFTStream.close = sk_stream_close;
+
+#ifdef SKIA_HARFBUZZ
+ fHBFace = NULL;
+#endif
+
}
// Will return 0 on failure
@@ -234,6 +268,27 @@ static void unref_ft_face(FT_Face face) {
SkASSERT("shouldn't get here, face not in list");
}
+void SkFaceRec::setupShaper(HB_ShaperItem* item) {
+ if (!fHBFace) {
+ fHBFace = HB_NewFace(fFace, hb_freetype_table_sfnt_get);
+ fHBFont = (HB_FontRec *) calloc(sizeof(HB_FontRec), 1);
+ fHBFont->klass = &hb_freetype_class;
+ fHBFont->userData = fFace;
+ fHBFont->x_ppem = fFace->size->metrics.x_ppem;
+ fHBFont->y_ppem = fFace->size->metrics.y_ppem;
+ fHBFont->x_scale = fFace->size->metrics.x_scale;
+ fHBFont->y_scale = fFace->size->metrics.y_scale;
+ }
+
+ item->face = fHBFace;
+ item->font = fHBFont;
+ fRefCnt++;
+}
+
+void SkFaceRec::releaseShaper(HB_ShaperItem* item) {
+ fRefCnt--;
+}
+
///////////////////////////////////////////////////////////////////////////
SkScalerContext_FreeType::SkScalerContext_FreeType(const SkDescriptor* desc)
@@ -649,6 +704,16 @@ void SkScalerContext_FreeType::generateImage(const SkGlyph& glyph) {
}
}
+#ifdef SKIA_HARFBUZZ
+void SkScalerContext_FreeType::setupShaper(HB_ShaperItem* item) {
+ fFaceRec->setupShaper(item);
+}
+
+void SkScalerContext_FreeType::releaseShaper(HB_ShaperItem* item) {
+ fFaceRec->releaseShaper(item);
+}
+#endif
+
///////////////////////////////////////////////////////////////////////////////
#define ft2sk(x) SkFixedToScalar((x) << 10)
diff --git a/skia/sgl/SkGlyphCache.cpp b/skia/sgl/SkGlyphCache.cpp
index 6b214df..9836c73 100644
--- a/skia/sgl/SkGlyphCache.cpp
+++ b/skia/sgl/SkGlyphCache.cpp
@@ -328,6 +328,18 @@ const SkPath* SkGlyphCache::findPath(const SkGlyph& glyph) {
///////////////////////////////////////////////////////////////////////////////
+#ifdef SKIA_HARFBUZZ
+void SkGlyphCache::setupShaper(HB_ShaperItem* item) {
+ fScalerContext->setupShaper(item);
+}
+
+void SkGlyphCache::releaseShaper(HB_ShaperItem* item) {
+ fScalerContext->releaseShaper(item);
+}
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+
bool SkGlyphCache::getAuxProcData(void (*proc)(void*), void** dataPtr) const {
const AuxProcRec* rec = fAuxProcList;
while (rec) {
diff --git a/skia/sgl/SkGlyphCache.h b/skia/sgl/SkGlyphCache.h
index 2462ea5..db9e8d5 100644
--- a/skia/sgl/SkGlyphCache.h
+++ b/skia/sgl/SkGlyphCache.h
@@ -27,6 +27,7 @@
class SkPaint;
class SkGlyphCache_Globals;
+typedef struct HB_ShaperItem_ HB_ShaperItem;
/** \class SkGlyphCache
@@ -86,6 +87,16 @@ public:
const SkPaint::FontMetrics& getFontMetricsY() const {
return fFontMetricsY;
}
+
+#ifdef SKIA_HARFBUZZ
+ /** Setup a Harfbuzz shaper item with the correct |font| and |face| members.
+ */
+ void setupShaper(HB_ShaperItem* item);
+ /** Release the given references associated with |item|.
+ */
+ void releaseShaper(HB_ShaperItem* item);
+#endif
+
/* AuxProc/Data allow a client to associate data with this cache entry.
Multiple clients can use this, as their data is keyed with a function
diff --git a/skia/sgl/SkPaint.cpp b/skia/sgl/SkPaint.cpp
index bb6b31e..5fc1f14 100644
--- a/skia/sgl/SkPaint.cpp
+++ b/skia/sgl/SkPaint.cpp
@@ -365,6 +365,18 @@ int SkPaint::textToGlyphs(const void* textData, size_t byteLength,
return gptr - glyphs;
}
+#ifdef SKIA_HARFBUZZ
+void SkPaint::setupShaper(HB_ShaperItem* item) {
+ SkAutoGlyphCache autoCache(*this, NULL);
+ autoCache.getCache()->setupShaper(item);
+}
+
+void SkPaint::releaseShaper(HB_ShaperItem* item) {
+ SkAutoGlyphCache autoCache(*this, NULL);
+ autoCache.getCache()->releaseShaper(item);
+}
+#endif
+
///////////////////////////////////////////////////////////////////////////////
static uint32_t sk_glyphID_next(const char** text)
diff --git a/skia/skia.gyp b/skia/skia.gyp
index bdf2de1..cd165bc 100644
--- a/skia/skia.gyp
+++ b/skia/skia.gyp
@@ -691,6 +691,8 @@
'../build/linux/system.gyp:gdk',
'../build/linux/system.gyp:fontconfig',
'../build/linux/system.gyp:freetype2',
+ '../third_party/harfbuzz/harfbuzz.gyp:harfbuzz',
+ '../third_party/harfbuzz/harfbuzz.gyp:harfbuzz_interface',
],
'cflags': [
'-Wno-unused',
@@ -700,6 +702,9 @@
'ports/SkFontHost_none.cpp',
'sgl/SkTypeface_fake.cpp',
],
+ 'defines': [
+ 'SKIA_HARFBUZZ',
+ ],
}],
[ 'OS == "mac"', {
'defines': [