Bug 1365776 - Use the IDWriteFontFace1 interface if available to get glyph advances from DirectWrite more cheaply. r=jrmuizel

This commit is contained in:
Jonathan Kew 2017-05-19 22:25:28 +01:00
Родитель fb4b3bc484
Коммит 3bcb26919c
2 изменённых файлов: 37 добавлений и 15 удалений

Просмотреть файл

@ -5,13 +5,10 @@
#include "gfxDWriteFonts.h" #include "gfxDWriteFonts.h"
#include "mozilla/MemoryReporting.h"
#include <algorithm> #include <algorithm>
#include "gfxDWriteFontList.h" #include "gfxDWriteFontList.h"
#include "gfxContext.h" #include "gfxContext.h"
#include "gfxTextRun.h" #include "gfxTextRun.h"
#include <dwrite.h>
#include "harfbuzz/hb.h" #include "harfbuzz/hb.h"
@ -95,6 +92,11 @@ gfxDWriteFont::gfxDWriteFont(const RefPtr<UnscaledFontDWrite>& aUnscaledFont,
mFontFace = aUnscaledFont->GetFontFace(); mFontFace = aUnscaledFont->GetFontFace();
// If the IDWriteFontFace1 interface is available, we can use that for
// faster glyph width retrieval.
mFontFace->QueryInterface(__uuidof(IDWriteFontFace1),
(void**)getter_AddRefs(mFontFace1));
ComputeMetrics(anAAOption); ComputeMetrics(anAAOption);
} }
@ -630,20 +632,38 @@ gfxDWriteFont::GetMeasuringMode()
gfxFloat gfxFloat
gfxDWriteFont::MeasureGlyphWidth(uint16_t aGlyph) gfxDWriteFont::MeasureGlyphWidth(uint16_t aGlyph)
{ {
DWRITE_GLYPH_METRICS metrics;
HRESULT hr; HRESULT hr;
if (mUseSubpixelPositions) { if (mFontFace1) {
hr = mFontFace->GetDesignGlyphMetrics(&aGlyph, 1, &metrics, FALSE); int32_t advance;
if (SUCCEEDED(hr)) { if (mUseSubpixelPositions) {
return metrics.advanceWidth * mFUnitsConvFactor; hr = mFontFace1->GetDesignGlyphAdvances(1, &aGlyph, &advance, FALSE);
if (SUCCEEDED(hr)) {
return advance * mFUnitsConvFactor;
}
} else {
hr = mFontFace1->GetGdiCompatibleGlyphAdvances(
FLOAT(mAdjustedSize), 1.0f, nullptr,
GetMeasuringMode() == DWRITE_MEASURING_MODE_GDI_NATURAL,
FALSE, 1, &aGlyph, &advance);
if (SUCCEEDED(hr)) {
return NS_lround(advance * mFUnitsConvFactor);
}
} }
} else { } else {
hr = mFontFace->GetGdiCompatibleGlyphMetrics( DWRITE_GLYPH_METRICS metrics;
FLOAT(mAdjustedSize), 1.0f, nullptr, if (mUseSubpixelPositions) {
GetMeasuringMode() == DWRITE_MEASURING_MODE_GDI_NATURAL, hr = mFontFace->GetDesignGlyphMetrics(&aGlyph, 1, &metrics, FALSE);
&aGlyph, 1, &metrics, FALSE); if (SUCCEEDED(hr)) {
if (SUCCEEDED(hr)) { return metrics.advanceWidth * mFUnitsConvFactor;
return NS_lround(metrics.advanceWidth * mFUnitsConvFactor); }
} else {
hr = mFontFace->GetGdiCompatibleGlyphMetrics(
FLOAT(mAdjustedSize), 1.0f, nullptr,
GetMeasuringMode() == DWRITE_MEASURING_MODE_GDI_NATURAL,
&aGlyph, 1, &metrics, FALSE);
if (SUCCEEDED(hr)) {
return NS_lround(metrics.advanceWidth * mFUnitsConvFactor);
}
} }
} }
return 0; return 0;

Просмотреть файл

@ -8,7 +8,7 @@
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
#include <dwrite.h> #include <dwrite_1.h>
#include "gfxFont.h" #include "gfxFont.h"
#include "gfxUserFontSet.h" #include "gfxUserFontSet.h"
@ -93,6 +93,8 @@ protected:
bool GetForceGDIClassic(); bool GetForceGDIClassic();
RefPtr<IDWriteFontFace> mFontFace; RefPtr<IDWriteFontFace> mFontFace;
RefPtr<IDWriteFontFace1> mFontFace1; // may be unavailable on older DWrite
cairo_font_face_t *mCairoFontFace; cairo_font_face_t *mCairoFontFace;
Metrics *mMetrics; Metrics *mMetrics;