mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:47:36 +00:00
LibPDF: Create basic object structure
This commit is the start of LibPDF, and introduces some basic structure objects. This emulates LibJS's Value structure, where Value is a simple class that can contain a pointer to a more complex Object class with more data. All of the basic PDF objects have a representation.
This commit is contained in:
parent
af9a7b1374
commit
a8f5b6aaa3
10 changed files with 637 additions and 0 deletions
60
Userland/Libraries/LibPDF/Value.cpp
Normal file
60
Userland/Libraries/LibPDF/Value.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibPDF/Object.h>
|
||||
#include <LibPDF/Value.h>
|
||||
|
||||
namespace PDF {
|
||||
|
||||
Value::~Value()
|
||||
{
|
||||
if (is_object())
|
||||
m_as_object->unref();
|
||||
}
|
||||
|
||||
Value& Value::operator=(const Value& other)
|
||||
{
|
||||
m_type = other.m_type;
|
||||
switch (m_type) {
|
||||
case Type::Null:
|
||||
break;
|
||||
case Type::Bool:
|
||||
m_as_bool = other.m_as_bool;
|
||||
break;
|
||||
case Type::Int:
|
||||
m_as_int = other.m_as_int;
|
||||
break;
|
||||
case Type::Float:
|
||||
m_as_float = other.m_as_float;
|
||||
break;
|
||||
case Type::Object:
|
||||
m_as_object = other.m_as_object;
|
||||
if (m_as_object)
|
||||
m_as_object->ref();
|
||||
break;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
String Value::to_string(int indent) const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::Null:
|
||||
return "null";
|
||||
case Type::Bool:
|
||||
return as_bool() ? "true" : "false";
|
||||
case Type::Int:
|
||||
return String::number(as_int());
|
||||
case Type::Float:
|
||||
return String::number(as_float());
|
||||
case Type::Object:
|
||||
return as_object()->to_string(indent);
|
||||
}
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue