2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
#ifndef MOZILLA_GFX_SCALEDFONTDWRITE_H_
|
|
|
|
#define MOZILLA_GFX_SCALEDFONTDWRITE_H_
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
#include <dwrite.h>
|
2012-08-09 00:17:04 +04:00
|
|
|
#include "ScaledFontBase.h"
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2012-03-29 22:53:44 +04:00
|
|
|
struct ID2D1GeometrySink;
|
2016-10-13 01:53:04 +03:00
|
|
|
struct gfxFontStyle;
|
2012-03-29 22:53:44 +04:00
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2017-06-30 21:09:05 +03:00
|
|
|
class NativeFontResourceDWrite;
|
|
|
|
class UnscaledFontDWrite;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class ScaledFontDWrite final : public ScaledFontBase {
|
2011-06-24 21:41:16 +04:00
|
|
|
public:
|
2017-04-14 21:11:00 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontDWrite, override)
|
2017-04-07 00:41:02 +03:00
|
|
|
ScaledFontDWrite(IDWriteFontFace* aFont,
|
|
|
|
const RefPtr<UnscaledFont>& aUnscaledFont, Float aSize)
|
|
|
|
: ScaledFontBase(aUnscaledFont, aSize),
|
2015-11-05 23:19:33 +03:00
|
|
|
mFontFace(aFont),
|
2016-09-08 19:34:10 +03:00
|
|
|
mUseEmbeddedBitmap(false),
|
2019-07-19 06:56:50 +03:00
|
|
|
mRenderingMode(DWRITE_RENDERING_MODE_DEFAULT),
|
2017-06-30 21:09:05 +03:00
|
|
|
mGamma(2.2f),
|
2019-11-09 16:03:47 +03:00
|
|
|
mContrast(1.0f),
|
|
|
|
mClearTypeLevel(1.0f) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-07 00:41:02 +03:00
|
|
|
ScaledFontDWrite(IDWriteFontFace* aFontFace,
|
|
|
|
const RefPtr<UnscaledFont>& aUnscaledFont, Float aSize,
|
2019-07-19 06:56:50 +03:00
|
|
|
bool aUseEmbeddedBitmap,
|
|
|
|
DWRITE_RENDERING_MODE aRenderingMode,
|
2019-08-13 10:15:25 +03:00
|
|
|
IDWriteRenderingParams* aParams, Float aGamma,
|
2019-11-09 16:03:47 +03:00
|
|
|
Float aContrast, Float aClearTypeLevel,
|
|
|
|
const gfxFontStyle* aStyle = nullptr);
|
2016-01-06 22:35:04 +03:00
|
|
|
|
2017-04-14 21:11:00 +03:00
|
|
|
FontType GetType() const override { return FontType::DWRITE; }
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2017-04-14 21:11:00 +03:00
|
|
|
already_AddRefed<Path> GetPathForGlyphs(const GlyphBuffer& aBuffer,
|
|
|
|
const DrawTarget* aTarget) override;
|
|
|
|
void CopyGlyphsToBuilder(const GlyphBuffer& aBuffer, PathBuilder* aBuilder,
|
|
|
|
const Matrix* aTransformHint) override;
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2019-01-14 03:16:17 +03:00
|
|
|
void CopyGlyphsToSink(const GlyphBuffer& aBuffer,
|
|
|
|
ID2D1SimplifiedGeometrySink* aSink);
|
2012-03-29 22:53:44 +04:00
|
|
|
|
2017-04-14 21:11:00 +03:00
|
|
|
bool CanSerialize() override { return true; }
|
2012-09-24 19:02:49 +04:00
|
|
|
|
2017-06-30 21:09:05 +03:00
|
|
|
bool GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton) override;
|
|
|
|
|
2017-10-05 22:26:01 +03:00
|
|
|
bool GetWRFontInstanceOptions(
|
|
|
|
Maybe<wr::FontInstanceOptions>* aOutOptions,
|
|
|
|
Maybe<wr::FontInstancePlatformOptions>* aOutPlatformOptions,
|
|
|
|
std::vector<FontVariation>* aOutVariations) override;
|
|
|
|
|
2017-04-14 21:11:00 +03:00
|
|
|
AntialiasMode GetDefaultAAMode() override;
|
2012-11-23 05:53:12 +04:00
|
|
|
|
2019-07-19 06:56:50 +03:00
|
|
|
bool UseEmbeddedBitmaps() const { return mUseEmbeddedBitmap; }
|
2019-08-13 10:15:25 +03:00
|
|
|
bool ForceGDIMode() const {
|
|
|
|
return mRenderingMode == DWRITE_RENDERING_MODE_GDI_CLASSIC;
|
|
|
|
}
|
2019-07-19 06:56:50 +03:00
|
|
|
DWRITE_RENDERING_MODE GetRenderingMode() const { return mRenderingMode; }
|
2016-09-08 19:34:10 +03:00
|
|
|
|
2019-09-13 18:47:32 +03:00
|
|
|
bool HasSyntheticBold() const {
|
|
|
|
return (mFontFace->GetSimulations() & DWRITE_FONT_SIMULATIONS_BOLD) != 0;
|
|
|
|
}
|
|
|
|
|
2012-08-09 00:17:04 +04:00
|
|
|
#ifdef USE_SKIA
|
2018-08-23 21:58:21 +03:00
|
|
|
SkTypeface* CreateSkTypeface() override;
|
2019-09-16 20:03:04 +03:00
|
|
|
void SetupSkFontDrawOptions(SkFont& aFont) override;
|
2016-10-13 01:53:04 +03:00
|
|
|
SkFontStyle mStyle;
|
2012-08-09 00:17:04 +04:00
|
|
|
#endif
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDWriteFontFace> mFontFace;
|
2016-09-08 19:34:10 +03:00
|
|
|
bool mUseEmbeddedBitmap;
|
2019-07-19 06:56:50 +03:00
|
|
|
DWRITE_RENDERING_MODE mRenderingMode;
|
2017-06-30 21:09:05 +03:00
|
|
|
// DrawTargetD2D1 requires the IDWriteRenderingParams,
|
|
|
|
// but we also separately need to store the gamma and contrast
|
|
|
|
// since Skia needs to be able to access these without having
|
|
|
|
// to use the full set of DWrite parameters (which would be
|
|
|
|
// required to recreate an IDWriteRenderingParams) in a
|
|
|
|
// DrawTargetRecording playback.
|
|
|
|
RefPtr<IDWriteRenderingParams> mParams;
|
|
|
|
Float mGamma;
|
|
|
|
Float mContrast;
|
2019-11-09 16:03:47 +03:00
|
|
|
Float mClearTypeLevel;
|
2016-01-05 13:08:56 +03:00
|
|
|
|
|
|
|
#ifdef USE_CAIRO_SCALED_FONT
|
2019-10-02 00:56:30 +03:00
|
|
|
cairo_font_face_t* CreateCairoFontFace(
|
|
|
|
cairo_font_options_t* aFontOptions) override;
|
|
|
|
void PrepareCairoScaledFont(cairo_scaled_font_t* aFont) override;
|
2016-01-05 13:08:56 +03:00
|
|
|
#endif
|
2012-03-19 23:20:17 +04:00
|
|
|
|
|
|
|
private:
|
2017-06-30 21:09:05 +03:00
|
|
|
friend class NativeFontResourceDWrite;
|
|
|
|
friend class UnscaledFontDWrite;
|
2012-03-19 23:20:17 +04:00
|
|
|
|
2017-06-30 21:09:05 +03:00
|
|
|
struct InstanceData {
|
|
|
|
explicit InstanceData(ScaledFontDWrite* aScaledFont)
|
|
|
|
: mUseEmbeddedBitmap(aScaledFont->mUseEmbeddedBitmap),
|
2019-09-13 18:47:32 +03:00
|
|
|
mApplySyntheticBold(aScaledFont->HasSyntheticBold()),
|
2019-07-19 06:56:50 +03:00
|
|
|
mRenderingMode(aScaledFont->mRenderingMode),
|
2017-06-30 21:09:05 +03:00
|
|
|
mGamma(aScaledFont->mGamma),
|
2019-11-09 16:03:47 +03:00
|
|
|
mContrast(aScaledFont->mContrast),
|
|
|
|
mClearTypeLevel(aScaledFont->mClearTypeLevel) {}
|
2017-06-30 21:09:05 +03:00
|
|
|
|
2018-09-06 04:55:53 +03:00
|
|
|
InstanceData(const wr::FontInstanceOptions* aOptions,
|
|
|
|
const wr::FontInstancePlatformOptions* aPlatformOptions);
|
|
|
|
|
2017-06-30 21:09:05 +03:00
|
|
|
bool mUseEmbeddedBitmap;
|
2019-09-13 18:47:32 +03:00
|
|
|
bool mApplySyntheticBold;
|
2019-07-19 06:56:50 +03:00
|
|
|
DWRITE_RENDERING_MODE mRenderingMode;
|
2017-06-30 21:09:05 +03:00
|
|
|
Float mGamma;
|
|
|
|
Float mContrast;
|
2019-11-09 16:03:47 +03:00
|
|
|
Float mClearTypeLevel;
|
2017-06-30 21:09:05 +03:00
|
|
|
};
|
2012-03-19 23:20:17 +04:00
|
|
|
};
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
} // namespace gfx
|
2011-05-26 23:41:33 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
#endif /* MOZILLA_GFX_SCALEDFONTDWRITE_H_ */
|