mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-11-07 13:39:55 +00:00
fix(libcairo): keep font options storage private
This commit is contained in:
1 parent
e207dcbf4e
commit
b2d817a3d3
1 file changed
+21
-13
@@ -1,23 +1,31 @@
|
||||
#include "prx/libcairo/include/InventoryExports.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
struct cairo_font_options_t {
|
||||
namespace {
|
||||
|
||||
struct CairoFontOptionsStorage {
|
||||
cairo_antialias_t antialias;
|
||||
cairo_subpixel_order_t subpixel_order;
|
||||
cairo_hint_style_t hint_style;
|
||||
cairo_hint_metrics_t hint_metrics;
|
||||
};
|
||||
|
||||
namespace {
|
||||
const CairoFontOptionsStorage nilOptions{};
|
||||
|
||||
const cairo_font_options_t nilOptions{};
|
||||
CairoFontOptionsStorage* Storage(cairo_font_options_t* options) {
|
||||
return reinterpret_cast<CairoFontOptionsStorage*>(options);
|
||||
}
|
||||
|
||||
const CairoFontOptionsStorage* Storage(const cairo_font_options_t* options) {
|
||||
return reinterpret_cast<const CairoFontOptionsStorage*>(options);
|
||||
}
|
||||
|
||||
bool Invalid(const cairo_font_options_t* options) {
|
||||
return options == nullptr || options == &nilOptions;
|
||||
return options == nullptr || Storage(options) == &nilOptions;
|
||||
}
|
||||
|
||||
cairo_font_options_t* Nil() {
|
||||
return const_cast<cairo_font_options_t*>(&nilOptions);
|
||||
return reinterpret_cast<cairo_font_options_t*>(const_cast<CairoFontOptionsStorage*>(&nilOptions));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,14 +33,14 @@ cairo_font_options_t* Nil() {
|
||||
extern "C" {
|
||||
|
||||
cairo_font_options_t* APS5_VABI cairo_font_options_create() {
|
||||
auto* options = static_cast<cairo_font_options_t*>(std::calloc(1, sizeof(cairo_font_options_t)));
|
||||
return options != nullptr ? options : Nil();
|
||||
auto* options = std::calloc(1, sizeof(CairoFontOptionsStorage));
|
||||
return options != nullptr ? static_cast<cairo_font_options_t*>(options) : Nil();
|
||||
}
|
||||
|
||||
cairo_font_options_t* APS5_VABI cairo_font_options_copy(const cairo_font_options_t* original) {
|
||||
if (Invalid(original)) return Nil();
|
||||
auto* options = cairo_font_options_create();
|
||||
if (options != Nil()) *options = *original;
|
||||
if (options != Nil()) *Storage(options) = *Storage(original);
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -41,23 +49,23 @@ void APS5_VABI cairo_font_options_destroy(cairo_font_options_t* options) {
|
||||
}
|
||||
|
||||
void APS5_VABI cairo_font_options_set_antialias(cairo_font_options_t* options, cairo_antialias_t antialias) {
|
||||
if (!Invalid(options)) options->antialias = antialias;
|
||||
if (!Invalid(options)) Storage(options)->antialias = antialias;
|
||||
}
|
||||
|
||||
cairo_antialias_t APS5_VABI cairo_font_options_get_antialias(const cairo_font_options_t* options) {
|
||||
return Invalid(options) ? CAIRO_ANTIALIAS_DEFAULT : options->antialias;
|
||||
return Invalid(options) ? CAIRO_ANTIALIAS_DEFAULT : Storage(options)->antialias;
|
||||
}
|
||||
|
||||
void APS5_VABI cairo_font_options_set_hint_style(cairo_font_options_t* options, cairo_hint_style_t hint_style) {
|
||||
if (!Invalid(options)) options->hint_style = hint_style;
|
||||
if (!Invalid(options)) Storage(options)->hint_style = hint_style;
|
||||
}
|
||||
|
||||
void APS5_VABI cairo_font_options_set_hint_metrics(cairo_font_options_t* options, cairo_hint_metrics_t hint_metrics) {
|
||||
if (!Invalid(options)) options->hint_metrics = hint_metrics;
|
||||
if (!Invalid(options)) Storage(options)->hint_metrics = hint_metrics;
|
||||
}
|
||||
|
||||
void APS5_VABI cairo_font_options_set_subpixel_order(cairo_font_options_t* options, cairo_subpixel_order_t subpixel_order) {
|
||||
if (!Invalid(options)) options->subpixel_order = subpixel_order;
|
||||
if (!Invalid(options)) Storage(options)->subpixel_order = subpixel_order;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user