ScaledFontDWrite.h (3137B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MOZILLA_GFX_SCALEDFONTDWRITE_H_ 8 #define MOZILLA_GFX_SCALEDFONTDWRITE_H_ 9 10 #include <dwrite.h> 11 #include "DWriteSettings.h" 12 #include "ScaledFontBase.h" 13 14 struct gfxFontStyle; 15 16 namespace mozilla { 17 namespace gfx { 18 19 class NativeFontResourceDWrite; 20 class UnscaledFontDWrite; 21 22 class ScaledFontDWrite final : public ScaledFontBase { 23 public: 24 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontDWrite, override) 25 ScaledFontDWrite(IDWriteFontFace* aFontFace, 26 const RefPtr<UnscaledFont>& aUnscaledFont, Float aSize, 27 bool aUseEmbeddedBitmap, bool aUseMultistrikeBold, 28 bool aGDIForced, const gfxFontStyle* aStyle); 29 30 FontType GetType() const override { return FontType::DWRITE; } 31 32 bool CanSerialize() override { return true; } 33 34 bool MayUseBitmaps() override; 35 36 bool GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton) override; 37 38 bool GetWRFontInstanceOptions( 39 Maybe<wr::FontInstanceOptions>* aOutOptions, 40 Maybe<wr::FontInstancePlatformOptions>* aOutPlatformOptions, 41 std::vector<FontVariation>* aOutVariations) override; 42 43 DWriteSettings& DWriteSettings() const; 44 45 AntialiasMode GetDefaultAAMode() override; 46 47 bool UseEmbeddedBitmaps() const { return mUseEmbeddedBitmap; } 48 bool UseMultistrikeBold() const { return mUseMultistrikeBold; } 49 bool ForceGDIMode() const { return mGDIForced; } 50 51 bool UseSubpixelPosition() const override { return !ForceGDIMode(); } 52 53 bool HasBoldSimulation() const { 54 return (mFontFace->GetSimulations() & DWRITE_FONT_SIMULATIONS_BOLD) != 0; 55 } 56 57 bool HasVariationSettings() override; 58 59 SkTypeface* CreateSkTypeface() override; 60 void SetupSkFontDrawOptions(SkFont& aFont) override; 61 SkFontStyle mStyle; 62 63 RefPtr<IDWriteFontFace> mFontFace; 64 bool mUseEmbeddedBitmap; 65 bool mUseMultistrikeBold = false; 66 bool mGDIForced = false; 67 68 cairo_font_face_t* CreateCairoFontFace( 69 cairo_font_options_t* aFontOptions) override; 70 void PrepareCairoScaledFont(cairo_scaled_font_t* aFont) override; 71 72 private: 73 friend class NativeFontResourceDWrite; 74 friend class UnscaledFontDWrite; 75 76 struct InstanceData { 77 explicit InstanceData(ScaledFontDWrite* aScaledFont) 78 : mUseEmbeddedBitmap(aScaledFont->mUseEmbeddedBitmap), 79 mUseBoldSimulation(aScaledFont->HasBoldSimulation()), 80 mUseMultistrikeBold(aScaledFont->UseMultistrikeBold()), 81 mGDIForced(aScaledFont->mGDIForced) {} 82 83 InstanceData(const wr::FontInstanceOptions* aOptions, 84 const wr::FontInstancePlatformOptions* aPlatformOptions); 85 86 bool mUseEmbeddedBitmap = false; 87 bool mUseBoldSimulation = false; 88 bool mUseMultistrikeBold = false; 89 bool mGDIForced = false; 90 }; 91 }; 92 93 } // namespace gfx 94 } // namespace mozilla 95 96 #endif /* MOZILLA_GFX_SCALEDFONTDWRITE_H_ */