2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-02-26 09:36:07 +03:00
|
|
|
|
|
|
|
#include "gfxDWriteFonts.h"
|
2013-06-30 20:26:39 +04:00
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2010-02-26 09:36:07 +03:00
|
|
|
#include "gfxDWriteFontList.h"
|
|
|
|
#include "gfxContext.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxTextRun.h"
|
2018-09-13 21:59:27 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2010-02-26 09:36:07 +03:00
|
|
|
|
2012-04-22 01:24:39 +04:00
|
|
|
#include "harfbuzz/hb.h"
|
2018-04-13 22:34:37 +03:00
|
|
|
#include "mozilla/FontPropertyTypes.h"
|
2010-06-11 23:14:38 +04:00
|
|
|
|
2013-05-16 20:29:20 +04:00
|
|
|
using namespace mozilla;
|
2012-03-19 23:20:18 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2011-01-04 19:58:31 +03:00
|
|
|
// Code to determine whether Windows is set to use ClearType font smoothing;
|
|
|
|
// based on private functions in cairo-win32-font.c
|
|
|
|
|
|
|
|
#ifndef SPI_GETFONTSMOOTHINGTYPE
|
|
|
|
# define SPI_GETFONTSMOOTHINGTYPE 0x200a
|
|
|
|
#endif
|
|
|
|
#ifndef FE_FONTSMOOTHINGCLEARTYPE
|
|
|
|
# define FE_FONTSMOOTHINGCLEARTYPE 2
|
|
|
|
#endif
|
|
|
|
|
2018-09-13 21:59:27 +03:00
|
|
|
// Cleartype can be dynamically enabled/disabled, so we have to allow for
|
|
|
|
// dynamically updating it.
|
|
|
|
static BYTE GetSystemTextQuality() {
|
|
|
|
BOOL font_smoothing;
|
|
|
|
UINT smoothing_type;
|
2011-01-04 19:58:31 +03:00
|
|
|
|
2018-09-13 21:59:27 +03:00
|
|
|
if (!SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &font_smoothing, 0)) {
|
|
|
|
return DEFAULT_QUALITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (font_smoothing) {
|
|
|
|
if (!SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smoothing_type,
|
|
|
|
0)) {
|
|
|
|
return DEFAULT_QUALITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (smoothing_type == FE_FONTSMOOTHINGCLEARTYPE) {
|
|
|
|
return CLEARTYPE_QUALITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ANTIALIASED_QUALITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DEFAULT_QUALITY;
|
2011-01-04 19:58:31 +03:00
|
|
|
}
|
|
|
|
|
2019-07-24 21:51:28 +03:00
|
|
|
#ifndef SPI_GETFONTSMOOTHINGCONTRAST
|
|
|
|
# define SPI_GETFONTSMOOTHINGCONTRAST 0x200c
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// "Retrieves a contrast value that is used in ClearType smoothing. Valid
|
|
|
|
// contrast values are from 1000 to 2200. The default value is 1400."
|
|
|
|
static FLOAT GetSystemGDIGamma() {
|
|
|
|
static FLOAT sGDIGamma = 0.0f;
|
|
|
|
if (!sGDIGamma) {
|
|
|
|
UINT value = 0;
|
|
|
|
if (!SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &value, 0) ||
|
|
|
|
value < 1000 || value > 2200) {
|
|
|
|
value = 1400;
|
|
|
|
}
|
|
|
|
sGDIGamma = value / 1000.0f;
|
|
|
|
}
|
|
|
|
return sGDIGamma;
|
|
|
|
}
|
|
|
|
|
2010-02-26 09:36:07 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// gfxDWriteFont
|
2017-04-07 00:41:02 +03:00
|
|
|
gfxDWriteFont::gfxDWriteFont(const RefPtr<UnscaledFontDWrite>& aUnscaledFont,
|
|
|
|
gfxFontEntry* aFontEntry,
|
2010-03-12 07:25:35 +03:00
|
|
|
const gfxFontStyle* aFontStyle,
|
2018-10-11 18:19:25 +03:00
|
|
|
RefPtr<IDWriteFontFace> aFontFace,
|
2010-06-10 22:19:51 +04:00
|
|
|
AntialiasOption anAAOption)
|
2017-04-07 00:41:02 +03:00
|
|
|
: gfxFont(aUnscaledFont, aFontEntry, aFontStyle, anAAOption),
|
2018-10-11 18:19:25 +03:00
|
|
|
mFontFace(aFontFace ? aFontFace : aUnscaledFont->GetFontFace()),
|
2012-07-30 18:20:58 +04:00
|
|
|
mMetrics(nullptr),
|
2011-10-17 18:59:28 +04:00
|
|
|
mUseSubpixelPositions(false),
|
|
|
|
mAllowManualShowGlyphs(true),
|
2018-03-20 16:46:40 +03:00
|
|
|
mAzureScaledFontUsedClearType(false) {
|
2017-05-20 00:25:28 +03:00
|
|
|
// If the IDWriteFontFace1 interface is available, we can use that for
|
|
|
|
// faster glyph width retrieval.
|
|
|
|
mFontFace->QueryInterface(__uuidof(IDWriteFontFace1),
|
|
|
|
(void**)getter_AddRefs(mFontFace1));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-06-03 08:31:08 +04:00
|
|
|
ComputeMetrics(anAAOption);
|
2010-02-26 09:36:07 +03:00
|
|
|
}
|
|
|
|
|
2019-10-02 00:56:30 +03:00
|
|
|
gfxDWriteFont::~gfxDWriteFont() { delete mMetrics; }
|
2010-02-26 09:36:07 +03:00
|
|
|
|
2018-09-13 21:59:27 +03:00
|
|
|
static void ForceFontUpdate() {
|
|
|
|
// update device context font cache
|
|
|
|
// Dirty but easiest way:
|
|
|
|
// Changing nsIPrefBranch entry which triggers callbacks
|
|
|
|
// and flows into calling mDeviceContext->FlushFontCache()
|
|
|
|
// to update the font cache in all the instance of Browsers
|
|
|
|
static const char kPrefName[] = "font.internaluseonly.changed";
|
|
|
|
bool fontInternalChange = Preferences::GetBool(kPrefName, false);
|
|
|
|
Preferences::SetBool(kPrefName, !fontInternalChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxDWriteFont::UpdateSystemTextQuality() {
|
|
|
|
BYTE newQuality = GetSystemTextQuality();
|
|
|
|
if (gfxVars::SystemTextQuality() != newQuality) {
|
|
|
|
gfxVars::SetSystemTextQuality(newQuality);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxDWriteFont::SystemTextQualityChanged() {
|
|
|
|
// If ClearType status has changed, update our value,
|
|
|
|
// flush cached stuff that depended on the old setting, and force
|
|
|
|
// reflow everywhere to ensure we are using correct glyph metrics.
|
|
|
|
ForceFontUpdate();
|
|
|
|
Factory::SetSystemTextQuality(gfxVars::SystemTextQuality());
|
|
|
|
gfxPlatform::FlushFontAndWordCaches();
|
|
|
|
gfxPlatform::ForceGlobalReflow();
|
2016-12-22 14:06:15 +03:00
|
|
|
}
|
|
|
|
|
2010-06-10 22:19:51 +04:00
|
|
|
UniquePtr<gfxFont> gfxDWriteFont::CopyWithAntialiasOption(
|
|
|
|
AntialiasOption anAAOption) {
|
2017-01-09 20:41:35 +03:00
|
|
|
auto entry = static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
|
2017-04-07 00:41:02 +03:00
|
|
|
RefPtr<UnscaledFontDWrite> unscaledFont =
|
|
|
|
static_cast<UnscaledFontDWrite*>(mUnscaledFont.get());
|
2018-10-11 18:19:25 +03:00
|
|
|
return MakeUnique<gfxDWriteFont>(unscaledFont, entry, &mStyle, mFontFace,
|
|
|
|
anAAOption);
|
2010-06-10 22:19:51 +04:00
|
|
|
}
|
|
|
|
|
2014-09-30 10:37:40 +04:00
|
|
|
const gfxFont::Metrics& gfxDWriteFont::GetHorizontalMetrics() {
|
2011-01-21 19:44:32 +03:00
|
|
|
return *mMetrics;
|
2010-02-26 09:36:07 +03:00
|
|
|
}
|
|
|
|
|
2011-03-24 06:01:14 +03:00
|
|
|
bool gfxDWriteFont::GetFakeMetricsForArialBlack(
|
|
|
|
DWRITE_FONT_METRICS* aFontMetrics) {
|
|
|
|
gfxFontStyle style(mStyle);
|
2018-04-13 22:34:37 +03:00
|
|
|
style.weight = FontWeight(700);
|
2011-03-24 06:01:14 +03:00
|
|
|
|
Bug 1449605 - part 1 - Rearrange thebes font code so that the decision whether to apply synthetic-bold is deferred until actually instantiating a font, not made during the font-matching process. r=jwatt
This rearranges how synthetic-bold use is determined in the font selection
& rendering code. Previously, we would decide during the font-selection
algorithm whether we need to apply synthetic-bold to the chosen face, and
then pass that decision through the fontgroup (storing it in the FamilyFace
entries of the mFonts array there) down to the actual rendering code that
instantiates fonts from the faces (font entries) we've selected.
That became a problem for variation fonts because in the case of a user
font, we may not have downloaded the resource yet, so we just have a "user
font container" entry, which carries the descriptors from the @font-face
rule and will fetch the actual resource when needed. But in the case of a
@font-face rule without a weight descriptor, we don't actually know at
font-selection time whether the face will support "true" bold (via a
variation axis) or not, so we can't reliably make the right decision about
applying synthetic bold.
So we now defer that decision until we actually instantiate a platform font
object to shape/measure/draw text. At that point, we have the requested
style and we also have the real font resource, so we can easily determine
whether fake-bold is required.
(This patch should not result in any visible behavior change; that will
come in a second patch now that the architecture supports it.)
2018-05-01 12:30:50 +03:00
|
|
|
gfxFontEntry* fe = gfxPlatformFontList::PlatformFontList()->FindFontForFamily(
|
2011-03-24 06:01:14 +03:00
|
|
|
NS_LITERAL_CSTRING("Arial"), &style);
|
|
|
|
if (!fe || fe == mFontEntry) {
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-03-24 06:01:14 +03:00
|
|
|
|
Bug 1449605 - part 1 - Rearrange thebes font code so that the decision whether to apply synthetic-bold is deferred until actually instantiating a font, not made during the font-matching process. r=jwatt
This rearranges how synthetic-bold use is determined in the font selection
& rendering code. Previously, we would decide during the font-selection
algorithm whether we need to apply synthetic-bold to the chosen face, and
then pass that decision through the fontgroup (storing it in the FamilyFace
entries of the mFonts array there) down to the actual rendering code that
instantiates fonts from the faces (font entries) we've selected.
That became a problem for variation fonts because in the case of a user
font, we may not have downloaded the resource yet, so we just have a "user
font container" entry, which carries the descriptors from the @font-face
rule and will fetch the actual resource when needed. But in the case of a
@font-face rule without a weight descriptor, we don't actually know at
font-selection time whether the face will support "true" bold (via a
variation axis) or not, so we can't reliably make the right decision about
applying synthetic bold.
So we now defer that decision until we actually instantiate a platform font
object to shape/measure/draw text. At that point, we have the requested
style and we also have the real font resource, so we can easily determine
whether fake-bold is required.
(This patch should not result in any visible behavior change; that will
come in a second patch now that the architecture supports it.)
2018-05-01 12:30:50 +03:00
|
|
|
RefPtr<gfxFont> font = fe->FindOrMakeFont(&style);
|
2011-03-24 06:01:14 +03:00
|
|
|
gfxDWriteFont* dwFont = static_cast<gfxDWriteFont*>(font.get());
|
|
|
|
dwFont->mFontFace->GetMetrics(aFontMetrics);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2011-03-24 06:01:14 +03:00
|
|
|
}
|
|
|
|
|
2011-06-03 08:31:08 +04:00
|
|
|
void gfxDWriteFont::ComputeMetrics(AntialiasOption anAAOption) {
|
2010-02-26 09:36:07 +03:00
|
|
|
DWRITE_FONT_METRICS fontMetrics;
|
2018-04-25 09:18:23 +03:00
|
|
|
if (!(mFontEntry->Weight().Min() == FontWeight(900) &&
|
|
|
|
mFontEntry->Weight().Max() == FontWeight(900) &&
|
2011-03-24 06:01:14 +03:00
|
|
|
!mFontEntry->IsUserFont() &&
|
2012-12-19 13:42:25 +04:00
|
|
|
mFontEntry->Name().EqualsLiteral("Arial Black") &&
|
2011-03-24 06:01:14 +03:00
|
|
|
GetFakeMetricsForArialBlack(&fontMetrics))) {
|
|
|
|
mFontFace->GetMetrics(&fontMetrics);
|
|
|
|
}
|
2010-02-26 09:36:07 +03:00
|
|
|
|
2015-04-21 09:10:40 +03:00
|
|
|
if (mStyle.sizeAdjust >= 0.0) {
|
2010-03-12 14:57:49 +03:00
|
|
|
gfxFloat aspect =
|
|
|
|
(gfxFloat)fontMetrics.xHeight / fontMetrics.designUnitsPerEm;
|
|
|
|
mAdjustedSize = mStyle.GetAdjustedSize(aspect);
|
|
|
|
} else {
|
|
|
|
mAdjustedSize = mStyle.size;
|
|
|
|
}
|
|
|
|
|
2011-06-03 08:31:08 +04:00
|
|
|
// Note that GetMeasuringMode depends on mAdjustedSize
|
|
|
|
if ((anAAOption == gfxFont::kAntialiasDefault && UsingClearType() &&
|
|
|
|
GetMeasuringMode() == DWRITE_MEASURING_MODE_NATURAL) ||
|
|
|
|
anAAOption == gfxFont::kAntialiasSubpixel) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mUseSubpixelPositions = true;
|
2011-06-03 08:31:08 +04:00
|
|
|
// note that this may be reset to FALSE if we determine that a bitmap
|
|
|
|
// strike is going to be used
|
|
|
|
}
|
|
|
|
|
2011-01-25 12:17:18 +03:00
|
|
|
gfxDWriteFontEntry* fe = static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
|
|
|
|
if (fe->IsCJKFont() && HasBitmapStrikeForSize(NS_lround(mAdjustedSize))) {
|
2011-01-21 13:36:28 +03:00
|
|
|
mAdjustedSize = NS_lround(mAdjustedSize);
|
2011-10-17 18:59:28 +04:00
|
|
|
mUseSubpixelPositions = false;
|
2011-01-21 22:26:30 +03:00
|
|
|
// if we have bitmaps, we need to tell Cairo NOT to use subpixel AA,
|
|
|
|
// to avoid the manual-subpixel codepath in cairo-d2d-surface.cpp
|
2011-02-15 23:55:01 +03:00
|
|
|
// which fails to render bitmap glyphs (see bug 626299).
|
|
|
|
// This option will be passed to the cairo_dwrite_scaled_font_t
|
|
|
|
// after creation.
|
2011-10-17 18:59:28 +04:00
|
|
|
mAllowManualShowGlyphs = false;
|
2011-01-21 13:36:28 +03:00
|
|
|
}
|
|
|
|
|
2011-01-21 19:44:32 +03:00
|
|
|
mMetrics = new gfxFont::Metrics;
|
|
|
|
::memset(mMetrics, 0, sizeof(*mMetrics));
|
2010-08-05 13:18:42 +04:00
|
|
|
|
2011-04-21 10:29:50 +04:00
|
|
|
mFUnitsConvFactor = float(mAdjustedSize / fontMetrics.designUnitsPerEm);
|
2010-02-26 09:36:07 +03:00
|
|
|
|
2018-09-25 18:34:53 +03:00
|
|
|
mMetrics->xHeight = fontMetrics.xHeight * mFUnitsConvFactor;
|
2014-11-18 13:19:54 +03:00
|
|
|
mMetrics->capHeight = fontMetrics.capHeight * mFUnitsConvFactor;
|
2010-08-05 13:18:42 +04:00
|
|
|
|
|
|
|
mMetrics->maxAscent = round(fontMetrics.ascent * mFUnitsConvFactor);
|
Bug 1458159 - Use rounding instead of ceiling on max{Ascent,Descent} for DWriteFont. r=jfkthame
The ceiling was introduced in bug 549190 for improve the consistency of
underline positioning. However, removing ceiling now doesn't seem to
regress the testcases in that bug, probably thanks to improvement in
other part.
The ceiling here causes us to have different font metrics than other
browsers on Windows, and can lead to webcompat issue. We also don't do
this for other backends. So it's probably better removing it in favor
of rounding.
There are several test changes:
* min-intrinsic-with-percents-across-elements.html changes result due to
height of wrapping div in reference page depends on line height, so a
fixed line height is set to work around the issue.
* 368020-1.html changes result because a slightly different line-height
triggers bug 1462514. It is changed to use fixed line-height to work
around the issue.
* 456147.xul is disabled because it compares XUL against HTML page, but
XUL has different approach to position text in its elements than HTML.
Specifically, XUL elements don't seem to respect line height while
HTML elements do. The original line height in the file was probably
chosen to make the HTML match XUL, so it seems to be non-trivial to
fix it in a platform-independent way.
* sizing-orthog-{vlr,vrl}-in-htb-{008,020}.xht fails due to text in <p>
after the testing block shifts 1px up for unknown reason.
MozReview-Commit-ID: 2WJG1AigWl1
--HG--
extra : source : 653c6b7480997c4e1dbead5f0441bc06a0605b7a
2018-05-22 04:43:30 +03:00
|
|
|
mMetrics->maxDescent = round(fontMetrics.descent * mFUnitsConvFactor);
|
2011-01-21 19:44:32 +03:00
|
|
|
mMetrics->maxHeight = mMetrics->maxAscent + mMetrics->maxDescent;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-01-21 19:44:32 +03:00
|
|
|
mMetrics->emHeight = mAdjustedSize;
|
|
|
|
mMetrics->emAscent =
|
|
|
|
mMetrics->emHeight * mMetrics->maxAscent / mMetrics->maxHeight;
|
|
|
|
mMetrics->emDescent = mMetrics->emHeight - mMetrics->emAscent;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-01-21 19:44:32 +03:00
|
|
|
mMetrics->maxAdvance = mAdjustedSize;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-08-05 13:18:42 +04:00
|
|
|
// try to get the true maxAdvance value from 'hhea'
|
2013-05-16 20:29:20 +04:00
|
|
|
gfxFontEntry::AutoTable hheaTable(GetFontEntry(),
|
|
|
|
TRUETYPE_TAG('h', 'h', 'e', 'a'));
|
|
|
|
if (hheaTable) {
|
|
|
|
uint32_t len;
|
|
|
|
const MetricsHeader* hhea = reinterpret_cast<const MetricsHeader*>(
|
|
|
|
hb_blob_get_data(hheaTable, &len));
|
|
|
|
if (len >= sizeof(MetricsHeader)) {
|
2011-04-21 10:29:50 +04:00
|
|
|
mMetrics->maxAdvance =
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t(hhea->advanceWidthMax) * mFUnitsConvFactor;
|
2010-08-05 13:18:42 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-08-05 13:18:42 +04:00
|
|
|
|
2011-04-21 10:29:50 +04:00
|
|
|
mMetrics->internalLeading =
|
|
|
|
std::max(mMetrics->maxHeight - mMetrics->emHeight, 0.0);
|
|
|
|
mMetrics->externalLeading = ceil(fontMetrics.lineGap * mFUnitsConvFactor);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-11-18 13:19:54 +03:00
|
|
|
UINT32 ucs = L' ';
|
|
|
|
UINT16 glyph;
|
2019-03-21 07:50:41 +03:00
|
|
|
if (SUCCEEDED(mFontFace->GetGlyphIndices(&ucs, 1, &glyph)) && glyph != 0) {
|
2014-11-18 13:19:54 +03:00
|
|
|
mSpaceGlyph = glyph;
|
2011-04-21 10:29:50 +04:00
|
|
|
mMetrics->spaceWidth = MeasureGlyphWidth(glyph);
|
2019-03-21 07:50:41 +03:00
|
|
|
} else {
|
|
|
|
mMetrics->spaceWidth = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2011-04-21 10:29:50 +04:00
|
|
|
// try to get aveCharWidth from the OS/2 table, fall back to measuring 'x'
|
|
|
|
// if the table is not available or if using hinted/pixel-snapped widths
|
|
|
|
if (mUseSubpixelPositions) {
|
|
|
|
mMetrics->aveCharWidth = 0;
|
2013-05-16 20:29:20 +04:00
|
|
|
gfxFontEntry::AutoTable os2Table(GetFontEntry(),
|
2011-01-21 13:36:28 +03:00
|
|
|
TRUETYPE_TAG('O', 'S', '/', '2'));
|
2013-05-16 20:29:20 +04:00
|
|
|
if (os2Table) {
|
|
|
|
uint32_t len;
|
|
|
|
const OS2Table* os2 =
|
2011-01-21 13:36:28 +03:00
|
|
|
reinterpret_cast<const OS2Table*>(hb_blob_get_data(os2Table, &len));
|
2014-10-01 23:25:48 +04:00
|
|
|
if (len >= 4) {
|
2011-04-21 10:29:50 +04:00
|
|
|
// Not checking against sizeof(mozilla::OS2Table) here because older
|
|
|
|
// versions of the table have different sizes; we only need the first
|
|
|
|
// two 16-bit fields here.
|
|
|
|
mMetrics->aveCharWidth =
|
|
|
|
int16_t(os2->xAvgCharWidth) * mFUnitsConvFactor;
|
2010-08-05 13:18:42 +04:00
|
|
|
}
|
2010-02-26 09:36:07 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-08-05 13:18:42 +04:00
|
|
|
|
2011-01-21 19:44:32 +03:00
|
|
|
if (mMetrics->aveCharWidth < 1) {
|
2010-02-26 09:36:07 +03:00
|
|
|
ucs = L'x';
|
2019-03-21 07:50:41 +03:00
|
|
|
if (SUCCEEDED(mFontFace->GetGlyphIndices(&ucs, 1, &glyph)) && glyph != 0) {
|
2011-04-21 10:29:50 +04:00
|
|
|
mMetrics->aveCharWidth = MeasureGlyphWidth(glyph);
|
|
|
|
}
|
|
|
|
if (mMetrics->aveCharWidth < 1) {
|
2011-01-21 19:44:32 +03:00
|
|
|
// Let's just assume the X is square.
|
|
|
|
mMetrics->aveCharWidth = fontMetrics.xHeight * mFUnitsConvFactor;
|
2010-02-26 09:36:07 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2010-08-05 13:18:42 +04:00
|
|
|
ucs = L'0';
|
2019-03-21 07:50:41 +03:00
|
|
|
if (SUCCEEDED(mFontFace->GetGlyphIndices(&ucs, 1, &glyph)) && glyph != 0) {
|
|
|
|
mMetrics->zeroWidth = MeasureGlyphWidth(glyph);
|
|
|
|
} else {
|
|
|
|
mMetrics->zeroWidth = -1.0; // indicates not found
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-08-05 13:18:42 +04:00
|
|
|
|
2011-04-21 10:29:50 +04:00
|
|
|
mMetrics->underlineOffset = fontMetrics.underlinePosition * mFUnitsConvFactor;
|
|
|
|
mMetrics->underlineSize = fontMetrics.underlineThickness * mFUnitsConvFactor;
|
|
|
|
mMetrics->strikeoutOffset =
|
|
|
|
fontMetrics.strikethroughPosition * mFUnitsConvFactor;
|
|
|
|
mMetrics->strikeoutSize =
|
|
|
|
fontMetrics.strikethroughThickness * mFUnitsConvFactor;
|
2010-02-26 09:36:07 +03:00
|
|
|
|
2011-01-21 19:44:32 +03:00
|
|
|
SanitizeMetrics(mMetrics, GetFontEntry()->mIsBadUnderlineFont);
|
2010-03-31 16:46:18 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
printf("Font: %p (%s) size: %f\n", this,
|
|
|
|
NS_ConvertUTF16toUTF8(GetName()).get(), mStyle.size);
|
2011-01-21 19:44:32 +03:00
|
|
|
printf(" emHeight: %f emAscent: %f emDescent: %f\n", mMetrics->emHeight, mMetrics->emAscent, mMetrics->emDescent);
|
|
|
|
printf(" maxAscent: %f maxDescent: %f maxAdvance: %f\n", mMetrics->maxAscent, mMetrics->maxDescent, mMetrics->maxAdvance);
|
|
|
|
printf(" internalLeading: %f externalLeading: %f\n", mMetrics->internalLeading, mMetrics->externalLeading);
|
2019-03-21 07:50:41 +03:00
|
|
|
printf(" spaceWidth: %f aveCharWidth: %f zeroWidth: %f\n",
|
|
|
|
mMetrics->spaceWidth, mMetrics->aveCharWidth, mMetrics->zeroWidth);
|
2016-08-18 12:43:54 +03:00
|
|
|
printf(" xHeight: %f capHeight: %f\n", mMetrics->xHeight, mMetrics->capHeight);
|
2014-06-28 10:40:36 +04:00
|
|
|
printf(" uOff: %f uSize: %f stOff: %f stSize: %f\n",
|
|
|
|
mMetrics->underlineOffset, mMetrics->underlineSize, mMetrics->strikeoutOffset, mMetrics->strikeoutSize);
|
2010-03-31 16:46:18 +04:00
|
|
|
#endif
|
|
|
|
}
|
2010-02-26 09:36:07 +03:00
|
|
|
|
2011-01-21 13:36:28 +03:00
|
|
|
using namespace mozilla; // for AutoSwap_* types
|
|
|
|
|
|
|
|
struct EBLCHeader {
|
|
|
|
AutoSwap_PRUint32 version;
|
|
|
|
AutoSwap_PRUint32 numSizes;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SbitLineMetrics {
|
2012-08-22 19:56:38 +04:00
|
|
|
int8_t ascender;
|
|
|
|
int8_t descender;
|
|
|
|
uint8_t widthMax;
|
|
|
|
int8_t caretSlopeNumerator;
|
|
|
|
int8_t caretSlopeDenominator;
|
|
|
|
int8_t caretOffset;
|
|
|
|
int8_t minOriginSB;
|
|
|
|
int8_t minAdvanceSB;
|
|
|
|
int8_t maxBeforeBL;
|
|
|
|
int8_t minAfterBL;
|
|
|
|
int8_t pad1;
|
|
|
|
int8_t pad2;
|
2011-01-21 13:36:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BitmapSizeTable {
|
|
|
|
AutoSwap_PRUint32 indexSubTableArrayOffset;
|
|
|
|
AutoSwap_PRUint32 indexTablesSize;
|
|
|
|
AutoSwap_PRUint32 numberOfIndexSubTables;
|
|
|
|
AutoSwap_PRUint32 colorRef;
|
|
|
|
SbitLineMetrics hori;
|
|
|
|
SbitLineMetrics vert;
|
|
|
|
AutoSwap_PRUint16 startGlyphIndex;
|
|
|
|
AutoSwap_PRUint16 endGlyphIndex;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t ppemX;
|
|
|
|
uint8_t ppemY;
|
|
|
|
uint8_t bitDepth;
|
|
|
|
uint8_t flags;
|
2011-01-21 13:36:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef EBLCHeader EBSCHeader;
|
|
|
|
|
|
|
|
struct BitmapScaleTable {
|
|
|
|
SbitLineMetrics hori;
|
|
|
|
SbitLineMetrics vert;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t ppemX;
|
|
|
|
uint8_t ppemY;
|
|
|
|
uint8_t substitutePpemX;
|
|
|
|
uint8_t substitutePpemY;
|
2011-01-21 13:36:28 +03:00
|
|
|
};
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
bool gfxDWriteFont::HasBitmapStrikeForSize(uint32_t aSize) {
|
|
|
|
uint8_t* tableData;
|
|
|
|
uint32_t len;
|
2011-01-21 13:36:28 +03:00
|
|
|
void* tableContext;
|
|
|
|
BOOL exists;
|
|
|
|
HRESULT hr = mFontFace->TryGetFontTable(
|
|
|
|
DWRITE_MAKE_OPENTYPE_TAG('E', 'B', 'L', 'C'), (const void**)&tableData,
|
|
|
|
&len, &tableContext, &exists);
|
|
|
|
if (FAILED(hr)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-01-21 13:36:28 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasStrike = false;
|
2011-01-21 13:36:28 +03:00
|
|
|
// not really a loop, but this lets us use 'break' to skip out of the block
|
|
|
|
// as soon as we know the answer, and skips it altogether if the table is
|
|
|
|
// not present
|
|
|
|
while (exists) {
|
|
|
|
if (len < sizeof(EBLCHeader)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const EBLCHeader* hdr = reinterpret_cast<const EBLCHeader*>(tableData);
|
|
|
|
if (hdr->version != 0x00020000) {
|
|
|
|
break;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numSizes = hdr->numSizes;
|
2011-01-21 13:36:28 +03:00
|
|
|
if (numSizes > 0xffff) { // sanity-check, prevent overflow below
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (len < sizeof(EBLCHeader) + numSizes * sizeof(BitmapSizeTable)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const BitmapSizeTable* sizeTable =
|
|
|
|
reinterpret_cast<const BitmapSizeTable*>(hdr + 1);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < numSizes; ++i, ++sizeTable) {
|
2011-01-21 13:36:28 +03:00
|
|
|
if (sizeTable->ppemX == aSize && sizeTable->ppemY == aSize) {
|
|
|
|
// we ignore a strike that contains fewer than 4 glyphs,
|
|
|
|
// as that probably indicates a font such as Courier New
|
|
|
|
// that provides bitmaps ONLY for the "shading" characters
|
|
|
|
// U+2591..2593
|
2012-08-22 19:56:38 +04:00
|
|
|
hasStrike = (uint16_t(sizeTable->endGlyphIndex) >=
|
|
|
|
uint16_t(sizeTable->startGlyphIndex) + 3);
|
2011-01-21 13:36:28 +03:00
|
|
|
break;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-01-21 13:36:28 +03:00
|
|
|
}
|
|
|
|
// if we reach here, we didn't find a strike; unconditionally break
|
|
|
|
// out of the while-loop block
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
}
|
2011-01-21 13:36:28 +03:00
|
|
|
mFontFace->ReleaseFontTable(tableContext);
|
|
|
|
|
|
|
|
if (hasStrike) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2011-01-21 13:36:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we didn't find a real strike, check if the font calls for scaling
|
|
|
|
// another bitmap to this size
|
|
|
|
hr = mFontFace->TryGetFontTable(DWRITE_MAKE_OPENTYPE_TAG('E', 'B', 'S', 'C'),
|
|
|
|
(const void**)&tableData, &len, &tableContext,
|
|
|
|
&exists);
|
|
|
|
if (FAILED(hr)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-01-21 13:36:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
while (exists) {
|
|
|
|
if (len < sizeof(EBSCHeader)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const EBSCHeader* hdr = reinterpret_cast<const EBSCHeader*>(tableData);
|
|
|
|
if (hdr->version != 0x00020000) {
|
|
|
|
break;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numSizes = hdr->numSizes;
|
2011-01-21 13:36:28 +03:00
|
|
|
if (numSizes > 0xffff) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (len < sizeof(EBSCHeader) + numSizes * sizeof(BitmapScaleTable)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const BitmapScaleTable* scaleTable =
|
|
|
|
reinterpret_cast<const BitmapScaleTable*>(hdr + 1);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < numSizes; ++i, ++scaleTable) {
|
2011-01-21 13:36:28 +03:00
|
|
|
if (scaleTable->ppemX == aSize && scaleTable->ppemY == aSize) {
|
2011-10-17 18:59:28 +04:00
|
|
|
hasStrike = true;
|
2011-01-21 13:36:28 +03:00
|
|
|
break;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-01-21 13:36:28 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
}
|
2011-01-21 13:36:28 +03:00
|
|
|
mFontFace->ReleaseFontTable(tableContext);
|
|
|
|
|
|
|
|
return hasStrike;
|
|
|
|
}
|
|
|
|
|
2014-11-17 12:59:50 +03:00
|
|
|
bool gfxDWriteFont::IsValid() const { return mFontFace != nullptr; }
|
2011-01-21 19:44:32 +03:00
|
|
|
|
|
|
|
IDWriteFontFace* gfxDWriteFont::GetFontFace() { return mFontFace.get(); }
|
|
|
|
|
2016-06-27 19:41:55 +03:00
|
|
|
gfxFont::RunMetrics gfxDWriteFont::Measure(const gfxTextRun* aTextRun,
|
2015-12-16 00:56:41 +03:00
|
|
|
uint32_t aStart, uint32_t aEnd,
|
|
|
|
BoundingBoxType aBoundingBoxType,
|
|
|
|
DrawTarget* aRefDrawTarget,
|
|
|
|
Spacing* aSpacing,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags aOrientation) {
|
2011-07-01 10:38:17 +04:00
|
|
|
gfxFont::RunMetrics metrics =
|
2015-12-16 00:56:41 +03:00
|
|
|
gfxFont::Measure(aTextRun, aStart, aEnd, aBoundingBoxType, aRefDrawTarget,
|
|
|
|
aSpacing, aOrientation);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-07-01 10:38:17 +04:00
|
|
|
// if aBoundingBoxType is LOOSE_INK_EXTENTS
|
|
|
|
// and the underlying cairo font may be antialiased,
|
|
|
|
// we can't trust Windows to have considered all the pixels
|
|
|
|
// so we need to add "padding" to the bounds.
|
|
|
|
// (see bugs 475968, 439831, compare also bug 445087)
|
|
|
|
if (aBoundingBoxType == LOOSE_INK_EXTENTS &&
|
|
|
|
mAntialiasOption != kAntialiasNone &&
|
|
|
|
GetMeasuringMode() == DWRITE_MEASURING_MODE_GDI_CLASSIC &&
|
2017-12-19 23:48:39 +03:00
|
|
|
metrics.mBoundingBox.Width() > 0) {
|
|
|
|
metrics.mBoundingBox.MoveByX(-aTextRun->GetAppUnitsPerDevUnit());
|
|
|
|
metrics.mBoundingBox.SetWidth(metrics.mBoundingBox.Width() +
|
|
|
|
aTextRun->GetAppUnitsPerDevUnit() * 3);
|
2011-07-01 10:38:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return metrics;
|
|
|
|
}
|
|
|
|
|
2014-06-09 18:47:31 +04:00
|
|
|
bool gfxDWriteFont::ProvidesGlyphWidths() const {
|
2011-02-15 23:55:01 +03:00
|
|
|
return !mUseSubpixelPositions ||
|
2018-01-18 20:45:24 +03:00
|
|
|
(mFontFace->GetSimulations() & DWRITE_FONT_SIMULATIONS_BOLD) ||
|
|
|
|
(((gfxDWriteFontEntry*)(GetFontEntry()))->HasVariations() &&
|
|
|
|
!mStyle.variationSettings.IsEmpty());
|
2011-02-15 23:55:01 +03:00
|
|
|
}
|
2011-01-21 19:44:33 +03:00
|
|
|
|
2018-12-31 14:43:27 +03:00
|
|
|
int32_t gfxDWriteFont::GetGlyphWidth(uint16_t aGID) {
|
2013-09-02 12:41:57 +04:00
|
|
|
if (!mGlyphWidths) {
|
2016-04-15 22:45:37 +03:00
|
|
|
mGlyphWidths = MakeUnique<nsDataHashtable<nsUint32HashKey, int32_t>>(128);
|
2011-01-04 19:58:31 +03:00
|
|
|
}
|
|
|
|
|
2011-04-21 10:29:50 +04:00
|
|
|
int32_t width = -1;
|
2013-09-02 12:41:57 +04:00
|
|
|
if (mGlyphWidths->Get(aGID, &width)) {
|
2011-04-21 10:29:50 +04:00
|
|
|
return width;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2011-04-21 10:29:50 +04:00
|
|
|
width = NS_lround(MeasureGlyphWidth(aGID) * 65536.0);
|
2013-09-02 12:41:57 +04:00
|
|
|
mGlyphWidths->Put(aGID, width);
|
2011-01-04 19:58:31 +03:00
|
|
|
return width;
|
2011-04-21 10:29:50 +04:00
|
|
|
}
|
|
|
|
|
2019-09-16 20:15:10 +03:00
|
|
|
bool gfxDWriteFont::GetForceGDIClassic() const {
|
2011-06-03 08:31:08 +04:00
|
|
|
return static_cast<gfxDWriteFontEntry*>(mFontEntry.get())
|
|
|
|
->GetForceGDIClassic() &&
|
2011-06-09 11:17:20 +04:00
|
|
|
cairo_dwrite_get_cleartype_rendering_mode() < 0 &&
|
2011-06-03 08:31:08 +04:00
|
|
|
GetAdjustedSize() <= gfxDWriteFontList::PlatformFontList()
|
|
|
|
->GetForceGDIClassicMaxFontSize();
|
|
|
|
}
|
|
|
|
|
2011-06-03 08:31:07 +04:00
|
|
|
DWRITE_MEASURING_MODE
|
2019-09-16 20:15:10 +03:00
|
|
|
gfxDWriteFont::GetMeasuringMode() const {
|
2011-06-03 08:31:08 +04:00
|
|
|
return GetForceGDIClassic()
|
2011-06-03 08:31:07 +04:00
|
|
|
? DWRITE_MEASURING_MODE_GDI_CLASSIC
|
|
|
|
: gfxWindowsPlatform::GetPlatform()->DWriteMeasuringMode();
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxFloat gfxDWriteFont::MeasureGlyphWidth(uint16_t aGlyph) {
|
2020-03-16 16:57:32 +03:00
|
|
|
MOZ_SEH_TRY {
|
|
|
|
HRESULT hr;
|
|
|
|
if (mFontFace1) {
|
|
|
|
int32_t advance;
|
|
|
|
if (mUseSubpixelPositions) {
|
|
|
|
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);
|
|
|
|
}
|
2017-05-20 00:25:28 +03:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-16 16:57:32 +03:00
|
|
|
DWRITE_GLYPH_METRICS metrics;
|
|
|
|
if (mUseSubpixelPositions) {
|
|
|
|
hr = mFontFace->GetDesignGlyphMetrics(&aGlyph, 1, &metrics, FALSE);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
return 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);
|
|
|
|
}
|
2017-05-20 00:25:28 +03:00
|
|
|
}
|
2011-01-04 19:58:31 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2020-03-16 16:57:32 +03:00
|
|
|
MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
// Exception (e.g. disk i/o error) occurred when DirectWrite tried to use
|
|
|
|
// the font resource; possibly a failing drive or similar hardware issue.
|
|
|
|
// Mark the font as invalid, and wipe the fontEntry's charmap so that font
|
|
|
|
// selection will skip it; we'll use a fallback font instead.
|
|
|
|
mIsValid = false;
|
|
|
|
GetFontEntry()->mCharacterMap = new gfxCharacterMap();
|
|
|
|
GetFontEntry()->mShmemCharacterMap = nullptr;
|
|
|
|
gfxCriticalError() << "Exception occurred measuring glyph width for "
|
|
|
|
<< GetFontEntry()->Name().get();
|
|
|
|
}
|
2019-03-21 07:50:41 +03:00
|
|
|
return 0.0;
|
2011-01-04 19:58:31 +03:00
|
|
|
}
|
2012-03-23 16:14:16 +04:00
|
|
|
|
2019-09-20 19:30:21 +03:00
|
|
|
bool gfxDWriteFont::GetGlyphBounds(uint16_t aGID, gfxRect* aBounds,
|
|
|
|
bool aTight) {
|
|
|
|
DWRITE_GLYPH_METRICS m;
|
|
|
|
HRESULT hr = mFontFace->GetDesignGlyphMetrics(&aGID, 1, &m, FALSE);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
gfxRect bounds(m.leftSideBearing, m.topSideBearing - m.verticalOriginY,
|
|
|
|
m.advanceWidth - m.leftSideBearing - m.rightSideBearing,
|
|
|
|
m.advanceHeight - m.topSideBearing - m.bottomSideBearing);
|
|
|
|
bounds.Scale(mFUnitsConvFactor);
|
|
|
|
// GetDesignGlyphMetrics returns 'ideal' glyph metrics, we need to pad to
|
|
|
|
// account for antialiasing.
|
|
|
|
if (!aTight && !aBounds->IsEmpty()) {
|
|
|
|
bounds.Inflate(1.0, 0.0);
|
|
|
|
}
|
|
|
|
*aBounds = bounds;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-15 06:19:47 +04:00
|
|
|
void gfxDWriteFont::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const {
|
|
|
|
gfxFont::AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
|
2013-09-02 12:41:57 +04:00
|
|
|
aSizes->mFontInstances += aMallocSizeOf(mMetrics);
|
|
|
|
if (mGlyphWidths) {
|
|
|
|
aSizes->mFontInstances +=
|
2015-07-31 07:19:57 +03:00
|
|
|
mGlyphWidths->ShallowSizeOfIncludingThis(aMallocSizeOf);
|
2013-09-02 12:41:57 +04:00
|
|
|
}
|
2012-03-23 16:14:16 +04:00
|
|
|
}
|
|
|
|
|
2013-10-15 06:19:47 +04:00
|
|
|
void gfxDWriteFont::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const {
|
2012-03-23 16:14:16 +04:00
|
|
|
aSizes->mFontInstances += aMallocSizeOf(this);
|
2013-10-15 06:19:47 +04:00
|
|
|
AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
|
2012-03-23 16:14:16 +04:00
|
|
|
}
|
2012-09-24 19:02:49 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<ScaledFont> gfxDWriteFont::GetScaledFont(
|
2012-09-24 19:02:49 +04:00
|
|
|
mozilla::gfx::DrawTarget* aTarget) {
|
2018-09-13 21:59:27 +03:00
|
|
|
if (mAzureScaledFontUsedClearType != UsingClearType()) {
|
2018-03-20 16:46:40 +03:00
|
|
|
mAzureScaledFont = nullptr;
|
|
|
|
}
|
2017-08-07 23:20:44 +03:00
|
|
|
if (!mAzureScaledFont) {
|
|
|
|
gfxDWriteFontEntry* fe = static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
|
|
|
|
bool forceGDI = GetForceGDIClassic();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-07 23:20:44 +03:00
|
|
|
IDWriteRenderingParams* params =
|
|
|
|
gfxWindowsPlatform::GetPlatform()->GetRenderingParams(
|
2018-09-13 21:59:27 +03:00
|
|
|
UsingClearType()
|
2017-08-07 23:20:44 +03:00
|
|
|
? (forceGDI ? gfxWindowsPlatform::TEXT_RENDERING_GDI_CLASSIC
|
|
|
|
: gfxWindowsPlatform::TEXT_RENDERING_NORMAL)
|
|
|
|
: gfxWindowsPlatform::TEXT_RENDERING_NO_CLEARTYPE);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-25 18:33:56 +03:00
|
|
|
DWRITE_RENDERING_MODE renderingMode = params->GetRenderingMode();
|
|
|
|
FLOAT gamma = params->GetGamma();
|
|
|
|
FLOAT contrast = params->GetEnhancedContrast();
|
2019-11-09 16:03:47 +03:00
|
|
|
FLOAT clearTypeLevel = params->GetClearTypeLevel();
|
2019-07-26 19:49:14 +03:00
|
|
|
if (forceGDI || renderingMode == DWRITE_RENDERING_MODE_GDI_CLASSIC) {
|
2019-07-25 18:33:56 +03:00
|
|
|
renderingMode = DWRITE_RENDERING_MODE_GDI_CLASSIC;
|
|
|
|
gamma = GetSystemGDIGamma();
|
|
|
|
contrast = 0.0f;
|
|
|
|
}
|
2019-07-24 21:51:28 +03:00
|
|
|
|
2019-07-30 05:55:48 +03:00
|
|
|
bool useEmbeddedBitmap =
|
|
|
|
(renderingMode == DWRITE_RENDERING_MODE_DEFAULT ||
|
|
|
|
renderingMode == DWRITE_RENDERING_MODE_GDI_CLASSIC) &&
|
|
|
|
fe->IsCJKFont() && HasBitmapStrikeForSize(NS_lround(mAdjustedSize));
|
|
|
|
|
2017-08-07 23:20:44 +03:00
|
|
|
const gfxFontStyle* fontStyle = GetStyle();
|
2016-10-13 01:53:04 +03:00
|
|
|
mAzureScaledFont = Factory::CreateScaledFontForDWriteFont(
|
|
|
|
mFontFace, fontStyle, GetUnscaledFont(), GetAdjustedSize(),
|
2019-11-09 16:03:47 +03:00
|
|
|
useEmbeddedBitmap, (int)renderingMode, params, gamma, contrast,
|
|
|
|
clearTypeLevel);
|
2017-08-07 23:20:44 +03:00
|
|
|
if (!mAzureScaledFont) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-07-04 17:56:40 +03:00
|
|
|
InitializeScaledFont();
|
2018-09-13 21:59:27 +03:00
|
|
|
mAzureScaledFontUsedClearType = UsingClearType();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-09-24 19:02:49 +04:00
|
|
|
|
2017-08-07 23:20:44 +03:00
|
|
|
RefPtr<ScaledFont> scaledFont(mAzureScaledFont);
|
|
|
|
return scaledFont.forget();
|
2012-09-24 19:02:49 +04:00
|
|
|
}
|
2019-09-16 20:15:10 +03:00
|
|
|
|
|
|
|
bool gfxDWriteFont::ShouldRoundXOffset(cairo_t* aCairo) const {
|
|
|
|
// show_glyphs is implemented on the font and so is used for all Cairo
|
|
|
|
// surface types; however, it may pixel-snap depending on the dwrite
|
|
|
|
// rendering mode
|
|
|
|
return GetForceGDIClassic() ||
|
|
|
|
gfxWindowsPlatform::GetPlatform()->DWriteMeasuringMode() !=
|
|
|
|
DWRITE_MEASURING_MODE_NATURAL;
|
|
|
|
}
|