ref: dd33a15477c8608bad8f35a9fa908ad2086c6d1d
parent: c626c599b018d47759a86629c1474b04480675c6
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Apr 10 18:03:20 EDT 2021
some op stubs
--- /dev/null
+++ b/op.c
@@ -1,0 +1,125 @@
+#include <u.h>
+#include <libc.h>
+#include "pdf.h"
+
+enum {
+ Evenodd = 1<<0,
+ Nonstroking = 1<<1,
+ Leading = 1<<2,
+ Nextline = 1<<3,
+
+ N = -1,
+};
+
+typedef struct Op Op;
+
+struct Op {
+ char *s;
+ int (*f)(Op *op, Object *argv);
+ int argc;
+ int flags;
+};
+
+static int
+gspush(Op *op, Object *argv)
+{
+}
+
+static int
+gspop(Op *op, Object *argv)
+{
+}
+
+static Op ops[] = {
+ /* 8.4.4 Graphics state operators */
+ {"q", gspush, 0,}, /* push the current graphics state (gs) on gs stack */
+ {"Q", gspop, 0,}, /* pop ^ */
+ {"cm", gsctm, 6,}, /* current transformation matrix (ctm) */
+ {"w", gswidth, 1,}, /* line width */
+ {"J", gscap, 1,}, /* line cap style */
+ {"j", gsjoin, 1,}, /* line join style */
+ {"M", gsmiterlim, 1,}, /* miter limit */
+ {"d", gsdash, 2,}, /* line dash pattern */
+ {"ri", gsintent, 1,}, /* colour rendering intent */
+ {"i", gsflatness, 1,}, /* flatness tolerance */
+ {"gs", gsstate, 1,}, /* graphics state parameters */
+
+ /* 8.5.2 Path construction operators */
+ {"m", pcmove, 2,}, /* move to coords */
+ {"l", pcline, 2,}, /* straight line to coords */
+ {"c", pccurve, 6,}, /* Bézier curve */
+ {"v", pccurve, 4,}, /* Bézier curve */
+ {"y", pccurve, 4,}, /* Bézier curve */
+ {"h", pcsubpath, 0}, /* close subpath */
+ {"re", pcrect, 4,}, /* rectangle */
+
+ /* 8.5.3 Path painting operators */
+ {"S", ppstroke, 0,}, /* stroke the path */
+ {"s", ppstrokec, 0,}, /* close and stroke */
+ {"f", ppfill, 0,}, /* fill */
+ {"F", ppfill, 0,}, /* same damn thing, but DEPRECATED */
+ {"f*", ppfill, 0, Evenodd,}, /* fill, even/odd rule */
+ {"B", ppfills, 0,}, /* fill and stroke */
+ {"B*", ppfills, 0, Evenodd,}, /* fill and stroke, even/odd rule */
+ {"b", ppfillcfs, 0,}, /* close, fill and stroke */
+ {"b*", ppfillcfs, 0, Evenodd,}, /* close, fill and stroke, even/odd rule */
+ {"n", ppc, 0, 0}, /* end the path */
+
+ /* 8.5.4 Clipping path operators */
+ {"W", cpclip, 0,}, /* clip */
+ {"W*", cpclip, 0, Evenodd,}, /* clip, even/odd rule */
+
+ /* 8.6.8 Colour operators */
+ {"CS", cspace, 1,}, /* colour space */
+ {"cs", cspace, 1, Nonstroking,}, /* colour space, nonstroking */
+ {"SC", ccolour, N,}, /* colour */
+ {"sc", ccolour, N, Nonstroking,}, /* colour, nonstroking */
+ {"SCN", ccolour2, N,}, /* color (more spaces) */
+ {"scn", ccolour2, N,}, /* color (more spaces), nonstroking */
+ {"G", cgray, 1,}, /* gray */
+ {"g", cgray, 1, Nonstroking,}, /* gray, nonstroking */
+ {"RG", crgb, 3,}, /* RGB */
+ {"rg", crgb, 3, Nonstroking,}, /* RGB, nonstroking */
+ {"K", ccmyk, 4,}, /* CMYK */
+ {"k", ccmyk, 4, Nonstroking,}, /* CMYK, nonstroking */
+
+ /* 8.7.4.2 Shading operator */
+ {"sh", sshade, 1,}, /* shading */
+
+ /* 8.8 External objects */
+ {"Do", eoobject, 1,}, /* paint XObject */
+
+ /* 8.9.7 Inline images */
+ {"BI", iibegin, 0,}, /* begin */
+ {"ID", iidata, 0,}, /* data */
+ {"EI", iiend, 0,}, /* end */
+
+ /* 9.3.1 Text state parameters */
+ {"Tc", tsspace, 1,}, /* spacing */
+ {"Tw", tswspace, 1,}, /* word spacing */
+ {"Tz", tshscale, 1,}, /* horizontal spacing */
+ {"TL", tslead, 1,}, /* leading */
+ {"Tf", tsfontsz, 1,}, /* font size */
+ {"Tr", tsrendmode, 1,}, /* rendeing mode */
+ {"Ts", tsrise, 1,}, /* rise */
+
+ /* 9.4.1 Text objects */
+ {"BT", tobegin, 0,}, /* begin */
+ {"ET", toend, 0,}, /* end */
+
+ /* 9.4.2 Text position operators */
+ {"Td", tpmove, 2,}, /* move, next line */
+ {"TD", tpmove, 2, Leading,}, /* move, next line, leading */
+ {"Tm", tpmatrix, 6,}, /* (line) matrix */
+ {"T*", tpmove0, 0, Leading,}, /* move, next line, leading */
+
+ /* 9.4.3 Text showing operators */
+ {"Tj", thshow, 1,}, /* show string */
+ {"'", thshow, 1, Nextline,}, /* next line & show */
+ {"\"", thshow, 3, Nextline|TwTc,}, /* next line, Tw, Tc & show */
+ {"TJ", thshowarr, 1,}, /* show array */
+
+ /* 9.6.4 Type 3 font operators */
+ {"d0", t3width, 2,}, /* width info */
+ {"d1", t3widthbb, 6,}, /* width & bounding box */
+};
--- a/pdf.h
+++ b/pdf.h
@@ -11,7 +11,10 @@
};
typedef struct Buffer Buffer;
+typedef struct D D;
typedef struct Filter Filter;
+typedef struct Font Font;
+typedef struct GS GS;
typedef struct KeyValue KeyValue;
typedef struct Object Object;
typedef struct Pdf Pdf;
@@ -20,6 +23,7 @@
typedef struct Stream Stream;
typedef struct Xref Xref;
+
struct Buffer {
uchar *b;
int ro;
@@ -81,6 +85,31 @@
struct KeyValue {
char *key;
Object *value;
+};
+
+struct D {
+ int *d;
+ int nd;
+ int phase;
+};
+
+struct Font {
+ Object *font;
+ double size;
+};
+
+struct GS {
+ Object *BG, *UCR, *UCR2, *TR, *TR2, *HT, *BM, *SMask, *UseBlackPTComp, *HTO;
+ int LW, LC, LJ, ML, RI, OP, op, OPM, SA, AIS, TK;
+ double SM, CA, ca;
+ struct {
+ Font *Font;
+ int nFont;
+ };
+ struct {
+ D *d;
+ int nd;
+ };
};
struct Pdf {
--- a/xref.c
+++ b/xref.c
@@ -105,7 +105,7 @@
return x;
}
-/* 7.5.8.3 */
+/* 7.5.8.3 Cross-reference stream data */
int
xrefreadstream(Pdf *pdf)
{