1 // Copyright 2023 Google LLC 2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 3 #ifndef SkPathBridge_DEFINED 4 #define SkPathBridge_DEFINED 5 6 #include <cstddef> 7 #include <cstdint> 8 9 namespace fontations_ffi { 10 11 /** C++ pure virtual interface type, exposed to Rust side to be able to write 12 * out variation design parameters to the caller-side allocated 13 * SkFontParameters::Variation::Axis. A direct cast or mapping between a shared 14 * C++/Rust struct and a Skia side struct is not possible because the 15 * hidden-axis flag is private on SkFontParameters::Variation::Axis. */ 16 class AxisWrapper { 17 public: 18 virtual ~AxisWrapper() = default; 19 virtual bool populate_axis( 20 size_t i, uint32_t axisTag, float min, float def, float max, bool hidden) = 0; 21 virtual size_t size() const = 0; 22 }; 23 24 struct ColorStop; 25 struct BridgeColorStops; 26 struct Transform; 27 struct FillLinearParams; 28 struct FillRadialParams; 29 struct FillSweepParams; 30 31 /** C++ pure virtual interface, exposed to Rust side for receiving COLRv0/COLRv1 drawing callback 32 * matching Skrifa's ColorPainter trait. */ 33 class ColorPainterWrapper { 34 public: 35 virtual ~ColorPainterWrapper() = default; 36 virtual bool is_bounds_mode() = 0; 37 virtual void push_transform(const Transform& transform) = 0; 38 virtual void pop_transform() = 0; 39 virtual void push_clip_glyph(uint16_t glyph_id) = 0; 40 virtual void push_clip_rectangle(float x_min, float y_min, float x_max, float y_max) = 0; 41 virtual void pop_clip() = 0; 42 43 // Paint*Gradient equivalents: 44 virtual void fill_solid(uint16_t palette_index, float alpha) = 0; 45 virtual void fill_linear(const FillLinearParams& fill_linear_params, 46 BridgeColorStops& stops, 47 uint8_t extend_mode) = 0; 48 virtual void fill_radial(const FillRadialParams& fill_radial_params, 49 BridgeColorStops& stops, 50 uint8_t extend_mode) = 0; 51 virtual void fill_sweep(const FillSweepParams&, 52 BridgeColorStops& stops, 53 uint8_t extend_mode) = 0; 54 55 // Optimized calls that allow a SkCanvas::drawPath() call. 56 virtual void fill_glyph_solid(uint16_t glyph_id, uint16_t palette_index, float alpha) = 0; 57 virtual void fill_glyph_radial(uint16_t glyph_id, 58 const fontations_ffi::Transform& transform, 59 const fontations_ffi::FillRadialParams& fill_radial_params, 60 fontations_ffi::BridgeColorStops& stops, 61 uint8_t) = 0; 62 virtual void fill_glyph_linear(uint16_t glyph_id, 63 const fontations_ffi::Transform& transform, 64 const fontations_ffi::FillLinearParams& fill_linear_params, 65 fontations_ffi::BridgeColorStops& stops, 66 uint8_t) = 0; 67 virtual void fill_glyph_sweep(uint16_t glyph_id, 68 const fontations_ffi::Transform& transform, 69 const fontations_ffi::FillSweepParams& fill_sweep_params, 70 fontations_ffi::BridgeColorStops& stops, 71 uint8_t) = 0; 72 73 virtual void push_layer(uint8_t colrV1CompositeMode) = 0; 74 virtual void pop_layer() = 0; 75 }; 76 77 } // namespace fontations_ffi 78 79 #endif 80