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 * from Skrifa path output functions to an SkPath type to capture and convert a 13 * glyph path. */ 14 class PathWrapper { 15 public: 16 virtual ~PathWrapper() = default; 17 virtual void move_to(float x, float y) = 0; 18 virtual void line_to(float x, float y) = 0; 19 virtual void quad_to(float cx0, float cy0, float x, float y) = 0; 20 virtual void curve_to(float cx0, float cy0, float cx1, float cy1, float x, float y) = 0; 21 virtual void close() = 0; 22 }; 23 24 /** C++ pure virtual interface type, exposed to Rust side to be able to write 25 * out variation design parameters to the caller-side allocated 26 * SkFontParameters::Variation::Axis. A direct cast or mapping between a shared 27 * C++/Rust struct and a Skia side struct is not possible because the 28 * hidden-axis flag is private on SkFontParameters::Variation::Axis. */ 29 class AxisWrapper { 30 public: 31 virtual ~AxisWrapper() = default; 32 virtual bool populate_axis( 33 size_t i, uint32_t axisTag, float min, float def, float max, bool hidden) = 0; 34 virtual size_t size() const = 0; 35 }; 36 37 struct ColorStop; 38 struct BridgeColorStops; 39 struct Transform; 40 struct FillLinearParams; 41 struct FillRadialParams; 42 struct FillSweepParams; 43 44 /** C++ pure virtual interface, exposed to Rust side for receiving COLRv0/COLRv1 drawing callback 45 * matching Skrifa's ColorPainter trait. */ 46 class ColorPainterWrapper { 47 public: 48 virtual ~ColorPainterWrapper() = default; 49 virtual void push_transform(const Transform& transform) = 0; 50 virtual void pop_transform() = 0; 51 virtual void push_clip_glyph(uint16_t glyph_id) = 0; 52 virtual void push_clip_rectangle(float x_min, float y_min, float x_max, float y_max) = 0; 53 virtual void pop_clip() = 0; 54 55 // Paint*Gradient equivalents: 56 virtual void fill_solid(uint16_t palette_index, float alpha) = 0; 57 virtual void fill_linear(const FillLinearParams& fill_linear_params, 58 BridgeColorStops& stops, 59 uint8_t extend_mode) = 0; 60 virtual void fill_radial(const FillRadialParams& fill_radial_params, 61 BridgeColorStops& stops, 62 uint8_t extend_mode) = 0; 63 virtual void fill_sweep(const FillSweepParams&, 64 BridgeColorStops& stops, 65 uint8_t extend_mode) = 0; 66 67 // Optimized calls that allow a SkCanvas::drawPath() call. 68 virtual void fill_glyph_solid(uint16_t glyph_id, uint16_t palette_index, float alpha) = 0; 69 virtual void fill_glyph_radial(uint16_t glyph_id, 70 const fontations_ffi::Transform& transform, 71 const fontations_ffi::FillRadialParams& fill_radial_params, 72 fontations_ffi::BridgeColorStops& stops, 73 uint8_t) = 0; 74 virtual void fill_glyph_linear(uint16_t glyph_id, 75 const fontations_ffi::Transform& transform, 76 const fontations_ffi::FillLinearParams& fill_linear_params, 77 fontations_ffi::BridgeColorStops& stops, 78 uint8_t) = 0; 79 virtual void fill_glyph_sweep(uint16_t glyph_id, 80 const fontations_ffi::Transform& transform, 81 const fontations_ffi::FillSweepParams& fill_sweep_params, 82 fontations_ffi::BridgeColorStops& stops, 83 uint8_t) = 0; 84 85 virtual void push_layer(uint8_t colrV1CompositeMode) = 0; 86 virtual void pop_layer() = 0; 87 }; 88 89 } // namespace fontations_ffi 90 91 #endif 92