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

LibPDF: Add basic color space support to the renderer

This commit only supports the three most basic color spaces:
DeviceGray, DeviceRGB, and DeviceCMYK
This commit is contained in:
Matthew Olsson 2021-05-23 12:53:38 -07:00 committed by Ali Mohammad Pur
parent f4941f5940
commit 534a2e95d2
3 changed files with 177 additions and 24 deletions

View file

@ -19,6 +19,19 @@
#include <LibPDF/Document.h>
#include <LibPDF/Object.h>
#define ENUMERATE_COLOR_SPACES(V) \
V(DeviceGray) \
V(DeviceRGB) \
V(DeviceCMYK) \
V(CalGray) \
V(CalRGB) \
V(Lab) \
V(ICCBased) \
V(Indexed) \
V(Pattern) \
V(Separation) \
V(DeviceN)
namespace PDF {
enum class LineCapStyle : u8 {
@ -60,8 +73,23 @@ struct TextState {
bool knockout { true };
};
class ColorSpace {
public:
enum class Type {
#define ENUM(name) name,
ENUMERATE_COLOR_SPACES(ENUM)
#undef ENUM
};
static Optional<ColorSpace::Type> color_space_from_string(const StringView&);
static Color default_color_for_color_space(ColorSpace::Type);
static Color color_from_parameters(ColorSpace::Type color_space, const Vector<Value>& args);
};
struct GraphicsState {
Gfx::AffineTransform ctm;
ColorSpace::Type stroke_color_space { ColorSpace::Type::DeviceGray };
ColorSpace::Type paint_color_space { ColorSpace::Type::DeviceGray };
Gfx::Color stroke_color { Gfx::Color::NamedColor::Black };
Gfx::Color paint_color { Gfx::Color::NamedColor::Black };
float line_width { 1.0f };
@ -91,6 +119,7 @@ private:
// shift is the manual advance given in the TJ command array
void show_text(const String&, int shift = 0);
ColorSpace::Type get_color_space(const Value&);
ALWAYS_INLINE const GraphicsState& state() const { return m_graphics_state_stack.last(); }
ALWAYS_INLINE GraphicsState& state() { return m_graphics_state_stack.last(); }
@ -103,6 +132,9 @@ private:
template<typename T>
ALWAYS_INLINE Gfx::Size<T> map(Gfx::Size<T>) const;
template<typename T>
ALWAYS_INLINE Gfx::Rect<T> map(Gfx::Rect<T>) const;
const Gfx::AffineTransform& calculate_text_rendering_matrix();
RefPtr<Document> m_document;