1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:27:35 +00:00

AK+Everywhere: Remove JsonValue APIs with implicit default values

This commit is contained in:
Dan Klishch 2024-01-12 20:52:38 -05:00 committed by Andrew Kaster
parent c49819cced
commit b5f1a48a7c
16 changed files with 132 additions and 106 deletions

View file

@ -47,10 +47,11 @@ void UsersMapWidget::get_users()
auto json_users = result.release_value().as_array();
for (size_t i = 0; i < json_users.size(); i++) {
auto const& json_user = json_users.at(i).as_object();
auto const& coordinates = json_user.get_array("coordinates"sv).release_value();
User user {
MUST(String::from_byte_string(json_user.get_byte_string("nick"sv).release_value())),
{ json_user.get_array("coordinates"sv).release_value().at(0).to_double(),
json_user.get_array("coordinates"sv).release_value().at(1).to_double() },
{ coordinates[0].get_double_with_precision_loss().value(),
coordinates[1].get_double_with_precision_loss().value() },
json_user.has_bool("contributor"sv),
};
m_users.value().append(user);

View file

@ -1469,7 +1469,7 @@ ImageEditor& MainWidget::create_new_editor(NonnullRefPtr<Image> image)
else
return;
image_editor.add_guide(PixelPaint::Guide::construct(orientation, offset_value->to_number<float>()));
image_editor.add_guide(PixelPaint::Guide::construct(orientation, offset_value->get_float_with_precision_loss().value_or(0)));
});
}

View file

@ -149,7 +149,7 @@ ErrorOr<Gfx::IntSize> Presentation::parse_presentation_size(JsonObject const& me
return Error::from_string_view("Width or aspect in incorrect format"sv);
// We intentionally discard floating-point data here. If you need more resolution, just use a larger width.
auto const width = maybe_width->to_number<int>();
auto const width = maybe_width->get_number_with_precision_loss<int>().value();
auto const aspect_parts = maybe_aspect->split_view(':');
if (aspect_parts.size() != 2)
return Error::from_string_view("Aspect specification must have the exact format `width:height`"sv);

View file

@ -8,6 +8,7 @@
#include "Presentation.h"
#include <AK/JsonObject.h>
#include <AK/URL.h>
#include <LibGUI/PropertyDeserializer.h>
#include <LibGfx/Font/FontStyleMapping.h>
#include <LibGfx/Rect.h>
@ -42,16 +43,8 @@ ErrorOr<NonnullRefPtr<SlideObject>> SlideObject::parse_slide_object(JsonObject c
void SlideObject::set_property(StringView name, JsonValue value)
{
if (name == "rect"sv) {
if (value.is_array() && value.as_array().size() == 4) {
Gfx::IntRect rect;
rect.set_x(value.as_array()[0].to_i32());
rect.set_y(value.as_array()[1].to_i32());
rect.set_width(value.as_array()[2].to_i32());
rect.set_height(value.as_array()[3].to_i32());
m_rect = rect;
}
}
if (name == "rect"sv)
m_rect = GUI::PropertyDeserializer<Gfx::IntRect> {}(value).release_value_but_fixme_should_propagate_errors();
m_properties.set(name, move(value));
}
@ -74,7 +67,7 @@ void Text::set_property(StringView name, JsonValue value)
} else if (name == "font-weight"sv) {
m_font_weight = Gfx::name_to_weight(value.as_string());
} else if (name == "font-size"sv) {
m_font_size_in_pt = value.to_float();
m_font_size_in_pt = value.get_float_with_precision_loss().value();
} else if (name == "text-alignment"sv) {
m_text_align = value.as_string();
}