summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibPDF/CommonNames.h31
-rw-r--r--Userland/Libraries/LibPDF/Renderer.cpp31
-rw-r--r--Userland/Libraries/LibPDF/Renderer.h1
3 files changed, 60 insertions, 3 deletions
diff --git a/Userland/Libraries/LibPDF/CommonNames.h b/Userland/Libraries/LibPDF/CommonNames.h
index b300c81396..d17999f206 100644
--- a/Userland/Libraries/LibPDF/CommonNames.h
+++ b/Userland/Libraries/LibPDF/CommonNames.h
@@ -9,25 +9,33 @@
#include <AK/FlyString.h>
#define ENUMERATE_COMMON_NAMES(V) \
+ V(AIS) \
V(ASCII85Decode) \
V(ASCIIHexDecode) \
+ V(BG) \
+ V(BG2) \
+ V(BM) \
V(BaseFont) \
V(BlackPoint) \
V(C) \
- V(CalRGB) \
+ V(CA) \
V(CCITTFaxDecode) \
+ V(CalRGB) \
V(ColorSpace) \
V(Contents) \
V(Count) \
V(CropBox) \
V(Crypt) \
+ V(D) \
V(DCTDecode) \
V(Dest) \
V(DeviceCMYK) \
V(DeviceGray) \
V(DeviceRGB) \
V(E) \
+ V(ExtGState) \
V(F) \
+ V(FL) \
V(Filter) \
V(First) \
V(Fit) \
@@ -41,35 +49,54 @@
V(Font) \
V(Gamma) \
V(H) \
+ V(HT) \
+ V(HTO) \
V(JBIG2Decode) \
V(JPXDecode) \
V(Kids) \
V(L) \
+ V(LC) \
+ V(LJ) \
+ V(LW) \
V(LZWDecode) \
V(Last) \
V(Length) \
V(Linearized) \
+ V(ML) \
V(Matrix) \
V(MediaBox) \
V(N) \
V(Next) \
V(O) \
+ V(OP) \
+ V(OPM) \
V(Outlines) \
V(P) \
V(Pages) \
V(Parent) \
V(Pattern) \
V(Prev) \
+ V(RI) \
V(Resources) \
V(Root) \
V(Rotate) \
V(RunLengthDecode) \
+ V(SA) \
+ V(SM) \
+ V(SMask) \
V(T) \
+ V(TK) \
+ V(TR) \
+ V(TR2) \
V(Title) \
V(Type) \
+ V(UCR) \
+ V(UseBlackPTComp) \
V(UserUnit) \
V(WhitePoint) \
- V(XYZ)
+ V(XYZ) \
+ V(ca) \
+ V(op)
namespace PDF {
diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp
index 814869c3eb..69187e8296 100644
--- a/Userland/Libraries/LibPDF/Renderer.cpp
+++ b/Userland/Libraries/LibPDF/Renderer.cpp
@@ -146,7 +146,15 @@ RENDERER_HANDLER(set_dash_pattern)
RENDERER_TODO(set_color_rendering_intent);
RENDERER_TODO(set_flatness_tolerance);
-RENDERER_TODO(set_graphics_state_from_dict);
+
+RENDERER_HANDLER(set_graphics_state_from_dict)
+{
+ VERIFY(m_page.resources->contains(CommonNames::ExtGState));
+ auto dict_name = m_document->resolve_to<NameObject>(args[0])->name();
+ auto ext_gstate_dict = m_page.resources->get_dict(m_document, CommonNames::ExtGState);
+ auto target_dict = ext_gstate_dict->get_dict(m_document, dict_name);
+ set_graphics_state_from_dict(target_dict);
+}
RENDERER_HANDLER(path_move)
{
@@ -475,6 +483,27 @@ Gfx::Rect<T> Renderer::map(Gfx::Rect<T> rect) const
return state().ctm.map(rect);
}
+void Renderer::set_graphics_state_from_dict(NonnullRefPtr<DictObject> dict)
+{
+ if (dict->contains(CommonNames::LW))
+ handle_set_line_width({ dict->get_value(CommonNames::LW) });
+
+ if (dict->contains(CommonNames::LC))
+ handle_set_line_cap({ dict->get_value(CommonNames::LC) });
+
+ if (dict->contains(CommonNames::LJ))
+ handle_set_line_join({ dict->get_value(CommonNames::LJ) });
+
+ if (dict->contains(CommonNames::ML))
+ handle_set_miter_limit({ dict->get_value(CommonNames::ML) });
+
+ if (dict->contains(CommonNames::D))
+ handle_set_dash_pattern(dict->get_array(m_document, CommonNames::D)->elements());
+
+ if (dict->contains(CommonNames::FL))
+ handle_set_flatness_tolerance({ dict->get_value(CommonNames::FL) });
+}
+
void Renderer::show_text(const String& string, int shift)
{
auto utf = Utf8View(string);
diff --git a/Userland/Libraries/LibPDF/Renderer.h b/Userland/Libraries/LibPDF/Renderer.h
index 36bd103d7a..9e662f0e83 100644
--- a/Userland/Libraries/LibPDF/Renderer.h
+++ b/Userland/Libraries/LibPDF/Renderer.h
@@ -92,6 +92,7 @@ private:
void handle_text_next_line_show_string(const Vector<Value>& args);
void handle_text_next_line_show_string_set_spacing(const Vector<Value>& args);
+ void set_graphics_state_from_dict(NonnullRefPtr<DictObject>);
// shift is the manual advance given in the TJ command array
void show_text(const String&, int shift = 0);
RefPtr<ColorSpace> get_color_space(const Value&);