MockScaledFont.h (2135B)
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 FUZZ_MOCKSCALEDFONT_H 8 #define FUZZ_MOCKSCALEDFONT_H 9 10 #include "mozilla/gfx/2D.h" 11 12 class MockUnscaledFont : public mozilla::gfx::UnscaledFont { 13 public: 14 using FontType = mozilla::gfx::FontType; 15 16 FontType GetType() const final { return FontType::UNKNOWN; } 17 }; 18 19 class MockScaledFont : public mozilla::gfx::ScaledFont { 20 public: 21 using FontType = mozilla::gfx::FontType; 22 using Float = mozilla::gfx::Float; 23 using Path = mozilla::gfx::Path; 24 using GlyphBuffer = mozilla::gfx::GlyphBuffer; 25 using DrawTarget = mozilla::gfx::DrawTarget; 26 using PathBuilder = mozilla::gfx::PathBuilder; 27 using Matrix = mozilla::gfx::Matrix; 28 29 MockScaledFont(const RefPtr<MockUnscaledFont>& aUnscaledFont, 30 hb_font_t* aHBFont) 31 : ScaledFont(aUnscaledFont), mHBFont(hb_font_reference(aHBFont)) {} 32 virtual ~MockScaledFont() { hb_font_destroy(mHBFont); } 33 34 FontType GetType() const final { return FontType::UNKNOWN; } 35 Float GetSize() const final { 36 int x, y; 37 hb_font_get_scale(mHBFont, &x, &y); 38 return Float(y / 65536.0); 39 } 40 already_AddRefed<Path> GetPathForGlyphs(const GlyphBuffer& aBuffer, 41 const DrawTarget* aTarget) final { 42 RefPtr builder = mozilla::gfx::Factory::CreateSimplePathBuilder(); 43 CopyGlyphsToBuilder(aBuffer, builder); 44 RefPtr path = builder->Finish(); 45 return path.forget(); 46 } 47 void CopyGlyphsToBuilder(const GlyphBuffer& aBuffer, PathBuilder* aBuilder, 48 const Matrix* aTransformHint = nullptr) final { 49 // We could use hb_font_get_glyph_shape to extract the glyph path here, 50 // but the COLRv1 parsing code doesn't actually use it (it just passes it 51 // through to Moz2D), so for now we'll just return an empty path. 52 } 53 54 private: 55 hb_font_t* mHBFont; 56 }; 57 58 #endif