Bug 738691 - Part 1: Add CopyGlyphsToBuilder API. r=jrmuizel

This commit is contained in:
Bas Schouten 2012-03-29 20:53:44 +02:00
parent eaa02a2931
commit 283bb94230
5 changed files with 42 additions and 3 deletions

View File

@ -485,6 +485,13 @@ public:
*/
virtual TemporaryRef<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget) = 0;
/* This copies the path describing the glyphs into a PathBuilder. We use this
* API rather than a generic API to append paths because it allows easier
* implementation in some backends, and more efficient implementation in
* others.
*/
virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder) = 0;
protected:
ScaledFont() {}
};

View File

@ -132,6 +132,14 @@ ScaledFontBase::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *a
return NULL;
}
void
ScaledFontBase::CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder)
{
// XXX - implement me
MOZ_ASSERT(false);
return;
}
#ifdef USE_CAIRO
void
ScaledFontBase::SetCairoScaledFont(cairo_scaled_font_t* font)

View File

@ -59,6 +59,9 @@ public:
virtual ~ScaledFontBase();
virtual TemporaryRef<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget);
virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder);
#ifdef USE_SKIA
virtual SkTypeface* GetSkTypeface() { return mTypeface; }
#endif

View File

@ -56,6 +56,24 @@ ScaledFontDWrite::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget
PathBuilderD2D *pathBuilderD2D =
static_cast<PathBuilderD2D*>(pathBuilder.get());
CopyGlyphsToSink(aBuffer, pathBuilderD2D->GetSink());
return pathBuilder->Finish();
}
void
ScaledFontDWrite::CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder)
{
// XXX - Check path builder type!
PathBuilderD2D *pathBuilderD2D =
static_cast<PathBuilderD2D*>(aBuilder);
CopyGlyphsToSink(aBuffer, pathBuilderD2D->GetSink());
}
void
ScaledFontDWrite::CopyGlyphsToSink(const GlyphBuffer &aBuffer, ID2D1GeometrySink *aSink)
{
std::vector<UINT16> indices;
std::vector<FLOAT> advances;
std::vector<DWRITE_GLYPH_OFFSET> offsets;
@ -72,9 +90,7 @@ ScaledFontDWrite::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget
mFontFace->GetGlyphRunOutline(mSize, &indices.front(), &advances.front(),
&offsets.front(), aBuffer.mNumGlyphs,
FALSE, FALSE, pathBuilderD2D->GetSink());
return pathBuilder->Finish();
FALSE, FALSE, aSink);
}
}

View File

@ -41,6 +41,8 @@
#include "2D.h"
#include <dwrite.h>
struct ID2D1GeometrySink;
namespace mozilla {
namespace gfx {
@ -55,10 +57,13 @@ public:
virtual FontType GetType() const { return FONT_DWRITE; }
virtual TemporaryRef<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget);
virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder);
private:
friend class DrawTargetD2D;
void CopyGlyphsToSink(const GlyphBuffer &aBuffer, ID2D1GeometrySink *aSink);
RefPtr<IDWriteFontFace> mFontFace;
Float mSize;
};