Bug 972161: Add ability to output font data for freetype fonts. r=jrmuizel

This commit is contained in:
Bas Schouten 2014-02-13 07:31:51 +01:00
parent 65082a4626
commit 47974ec8fe
3 changed files with 66 additions and 9 deletions

View File

@ -294,10 +294,7 @@ void RecordingFontUserDataDestroyFunc(void *aUserData)
RecordingFontUserData *userData =
static_cast<RecordingFontUserData*>(aUserData);
// TODO support font in b2g recordings
#ifndef MOZ_WIDGET_GONK
userData->recorder->RecordEvent(RecordedScaledFontDestruction(userData->refPtr));
#endif
delete userData;
}
@ -310,10 +307,7 @@ DrawTargetRecording::FillGlyphs(ScaledFont *aFont,
const GlyphRenderingOptions *aRenderingOptions)
{
if (!aFont->GetUserData(reinterpret_cast<UserDataKey*>(mRecorder.get()))) {
// TODO support font in b2g recordings
#ifndef MOZ_WIDGET_GONK
mRecorder->RecordEvent(RecordedScaledFontCreation(aFont, aFont));
#endif
RecordingFontUserData *userData = new RecordingFontUserData;
userData->refPtr = aFont;
userData->recorder = mRecorder;
@ -321,10 +315,7 @@ DrawTargetRecording::FillGlyphs(ScaledFont *aFont,
&RecordingFontUserDataDestroyFunc);
}
// TODO support font in b2g recordings
#ifndef MOZ_WIDGET_GONK
mRecorder->RecordEvent(RecordedFillGlyphs(this, aFont, aPattern, aOptions, aBuffer.mGlyphs, aBuffer.mNumGlyphs));
#endif
mFinalDT->FillGlyphs(aFont, aBuffer, aPattern, aOptions, aRenderingOptions);
}

View File

@ -17,6 +17,13 @@
#include "HelpersCairo.h"
#endif
#ifdef CAIRO_HAS_FT_FONT
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_TRUETYPE_TABLES_H
#include "cairo-ft.h"
#endif
#include <vector>
#include <cmath>
@ -184,6 +191,63 @@ ScaledFontBase::SetCairoScaledFont(cairo_scaled_font_t* font)
mScaledFont = font;
cairo_scaled_font_reference(mScaledFont);
}
bool
ScaledFontBase::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton)
{
#ifdef USE_CAIRO_SCALED_FONT
switch (cairo_scaled_font_get_type(mScaledFont)) {
#ifdef CAIRO_HAS_FT_FONT
case CAIRO_FONT_TYPE_FT:
{
FT_Face face = cairo_ft_scaled_font_lock_face(mScaledFont);
if (!face) {
gfxWarning() << "Failed to lock FT_Face for cairo font.";
cairo_ft_scaled_font_unlock_face(mScaledFont);
return false;
}
if (!FT_IS_SFNT(face)) {
if (face->stream && face->stream->base) {
aDataCallback((uint8_t*)&face->stream->base, face->stream->size, 0, mSize, aBaton);
cairo_ft_scaled_font_unlock_face(mScaledFont);
return true;
}
gfxWarning() << "Non sfnt font with non-memory stream.";
cairo_ft_scaled_font_unlock_face(mScaledFont);
return false;
}
// Get the length of the whole font
FT_ULong length = 0;
FT_Error error = FT_Load_Sfnt_Table(face, 0, 0, nullptr, &length);
if (error || !length) {
cairo_ft_scaled_font_unlock_face(mScaledFont);
gfxWarning() << "Failed to get font file from Freetype font. " << error;
return false;
}
// Get the font data
std::vector<FT_Byte> buffer(length);
FT_Load_Sfnt_Table(face, 0, 0, &buffer.front(), &length);
aDataCallback((uint8_t*)&buffer.front(), length, 0, mSize, aBaton);
cairo_ft_scaled_font_unlock_face(mScaledFont);
return true;
}
#endif
default:
return false;
}
#endif
return false;
}
#endif
}

View File

@ -35,6 +35,8 @@ public:
virtual TemporaryRef<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget);
virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder, BackendType aBackendType, const Matrix *aTransformHint);
virtual bool GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton);
float GetSize() { return mSize; }