зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1365776 - Use the IDWriteFontFace1 interface if available to get glyph advances from DirectWrite more cheaply. r=jrmuizel
This commit is contained in:
Родитель
fb4b3bc484
Коммит
3bcb26919c
|
@ -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;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче