summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2024-05-26 16:49:46 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2024-05-26 17:01:34 +0100
commitb6edd5e9870d815d51bf18f8892697a6324baa65 (patch)
tree9334e658820a0a3e9d32456dc47144970f00c63a
parented7576580b0d20067b93b2178b1bcce27e99e39b (diff)
downloadlibcss-b6edd5e9870d815d51bf18f8892697a6324baa65.tar.gz
libcss-b6edd5e9870d815d51bf18f8892697a6324baa65.tar.bz2
select/unit: Add internal angle-to-degrees converter
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r--src/select/unit.c13
-rw-r--r--src/select/unit.h11
2 files changed, 24 insertions, 0 deletions
diff --git a/src/select/unit.c b/src/select/unit.c
index 3294db3..5f0f179 100644
--- a/src/select/unit.c
+++ b/src/select/unit.c
@@ -511,3 +511,16 @@ css_error css_unit_compute_absolute_font_size(
return CSS_OK;
}
+
+/* Exported function, documented in utils/unit.h. */
+css_fixed css_unit_angle2deg(const css_unit unit, const css_fixed angle)
+{
+ if (unit == CSS_UNIT_GRAD) {
+ return FMUL(angle, FLTTOFIX(0.9));
+ } else if (unit == CSS_UNIT_RAD) {
+ return FDIV(FMUL(angle, INTTOFIX(180)), F_PI);
+ } else {
+ /* Must be degrees as DEG/RAD/GRAD are all angle kinds */
+ return angle;
+ }
+}
diff --git a/src/select/unit.h b/src/select/unit.h
index 6a677b6..8b5d905 100644
--- a/src/select/unit.h
+++ b/src/select/unit.h
@@ -39,4 +39,15 @@ css_error css_unit_compute_absolute_font_size(
css_fixed font_size_default,
css_hint *size);
+/**
+ * Convert any angle to degrees.
+ *
+ * It is invalid to call this with a unit which isn't of \ref UNIT_ANGLE
+ *
+ * \param[in] unit The unit the angle is in
+ * \param[in] angle The angle to convert
+ * \return the angle in degrees
+ */
+css_fixed css_unit_angle2deg(const css_unit unit, const css_fixed angle);
+
#endif