summaryrefslogtreecommitdiff
path: root/Build/source/libs/xpdf/xpdf-src/xpdf/Annot.h
blob: 6ba5ff490da7f34c952f2c10e5f1564af18fdce8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//========================================================================
//
// Annot.h
//
// Copyright 2000-2003 Glyph & Cog, LLC
//
//========================================================================

#ifndef ANNOT_H
#define ANNOT_H

#include <aconf.h>

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

class XRef;
class Catalog;
class Gfx;
class GfxFontDict;
class PDFDoc;

//------------------------------------------------------------------------
// AnnotBorderStyle
//------------------------------------------------------------------------

enum AnnotBorderType {
  annotBorderSolid,
  annotBorderDashed,
  annotBorderBeveled,
  annotBorderInset,
  annotBorderUnderlined
};

class AnnotBorderStyle {
public:

  AnnotBorderStyle(AnnotBorderType typeA, double widthA,
		   double *dashA, int dashLengthA,
		   double *colorA, int nColorCompsA);
  ~AnnotBorderStyle();

  AnnotBorderType getType() { return type; }
  double getWidth() { return width; }
  void getDash(double **dashA, int *dashLengthA)
    { *dashA = dash; *dashLengthA = dashLength; }
  int getNumColorComps() { return nColorComps; }
  double *getColor() { return color; }

private:

  AnnotBorderType type;
  double width;
  double *dash;
  int dashLength;
  double color[4];
  int nColorComps;
};

//------------------------------------------------------------------------

enum AnnotLineEndType {
  annotLineEndNone,
  annotLineEndSquare,
  annotLineEndCircle,
  annotLineEndDiamond,
  annotLineEndOpenArrow,
  annotLineEndClosedArrow,
  annotLineEndButt,
  annotLineEndROpenArrow,
  annotLineEndRClosedArrow,
  annotLineEndSlash
};

//------------------------------------------------------------------------
// Annot
//------------------------------------------------------------------------

class Annot {
public:

  Annot(PDFDoc *docA, Dict *dict, Ref *refA);
  ~Annot();
  GBool isOk() { return ok; }

  void draw(Gfx *gfx, GBool printing);

  GString *getType() { return type; }
  double getXMin() { return xMin; }
  double getYMin() { return yMin; }
  double getXMax() { return xMax; }
  double getYMax() { return yMax; }
  Object *getObject(Object *obj);

  // Check if point is inside the annotation rectangle.
  GBool inRect(double x, double y)
    { return xMin <= x && x <= xMax && yMin <= y && y <= yMax; }

  // Get appearance object.
  Object *getAppearance(Object *obj) { return appearance.fetch(xref, obj); }

  AnnotBorderStyle *getBorderStyle() { return borderStyle; }

  GBool match(Ref *refA)
    { return ref.num == refA->num && ref.gen == refA->gen; }

  void generateAnnotAppearance();

private:
 
  void generateLineAppearance();
  void generatePolyLineAppearance();
  void generatePolygonAppearance();
  void generateFreeTextAppearance();
  void setLineStyle(AnnotBorderStyle *bs, double *lineWidth);
  void setStrokeColor(double *color, int nComps);
  GBool setFillColor(Object *colorObj);
  AnnotLineEndType parseLineEndType(Object *obj);
  void adjustLineEndpoint(AnnotLineEndType lineEnd,
			  double x, double y, double dx, double dy,
			  double w, double *tx, double *ty);
  void drawLineArrow(AnnotLineEndType lineEnd,
		     double x, double y, double dx, double dy,
		     double w, GBool fill);
  void drawCircle(double cx, double cy, double r, const char *cmd);
  void drawCircleTopLeft(double cx, double cy, double r);
  void drawCircleBottomRight(double cx, double cy, double r);
  void drawText(GString *text, GString *da, int quadding, double margin,
		int rot);

  PDFDoc *doc;
  XRef *xref;			// the xref table for this PDF file
  Ref ref;			// object ref identifying this annotation
  GString *type;		// annotation type
  GString *appearanceState;	// appearance state name
  Object appearance;		// a reference to the Form XObject stream
				//   for the normal appearance
  GString *appearBuf;
  double xMin, yMin,		// annotation rectangle
         xMax, yMax;
  Guint flags;
  AnnotBorderStyle *borderStyle;
  Object ocObj;			// optional content entry
  GBool ok;
};

//------------------------------------------------------------------------
// Annots
//------------------------------------------------------------------------

class Annots {
public:

  // Build a list of Annot objects.
  Annots(PDFDoc *docA, Object *annotsObj);

  ~Annots();

  // Iterate through list of annotations.
  int getNumAnnots() { return nAnnots; }
  Annot *getAnnot(int i) { return annots[i]; }

  // If point <x>,<y> is in an annotation, return the associated
  // annotation; else return NULL.
  Annot *find(double x, double y);
  int findIdx(double x, double y);

  // Generate an appearance stream for any non-form-field annotation
  // that is missing it.
  void generateAnnotAppearances();

private:

  void scanFieldAppearances(Dict *node, Ref *ref, Dict *parent,
			    Dict *acroForm);

  Annot *findAnnot(Ref *ref);

  PDFDoc *doc;
  Annot **annots;
  int nAnnots;
};

#endif