00001
00007 #ifndef __NPWGraphics__
00008 #define __NPWGraphics__
00009
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif
00013
00014 #include "NPWBase.h"
00015
00022 NPWErr NPWGraphicsCmd(NPW *pdf, NPWConstText cmd, NPWConstText fmt, ...);
00023
00025 #define NPWGraphicsMove(pdf, x, y) \
00026 NPWGraphicsCmd(pdf, "m", "ff", (NPWFloat)(x), (NPWFloat)(y))
00028 #define NPWGraphicsLine(pdf, x, y) \
00029 NPWGraphicsCmd(pdf, "l", "ff", (NPWFloat)(x), (NPWFloat)(y))
00031 #define NPWGraphicsBezier(pdf, x1, y1, x2, y2, x3, y3) \
00032 NPWGraphicsCmd(pdf, "c", "ffffff", \
00033 (NPWFloat)(x1), (NPWFloat)(y1), (NPWFloat)(x2), (NPWFloat)(y2), (NPWFloat)(x3), (NPWFloat)(y3))
00035 #define NPWGraphicsClosePath(pdf) \
00036 NPWGraphicsCmd(pdf, "h", "")
00038 #define NPWGraphicsRectangle(pdf, x, y, w, h) \
00039 NPWGraphicsCmd(pdf, "re", "ffff", (NPWFloat)(x), (NPWFloat)(y), (NPWFloat)(w), (NPWFloat)(h))
00040
00042 #define NPWGraphicsEllipse(pdf, x0, y0, rx, ry) \
00043 do { \
00044 NPWGraphicsMove(pdf, (x0) - (rx), y0); \
00045 NPWGraphicsBezier(pdf, \
00046 (x0) - (rx), (y0) + (ry) * 55 / 100, \
00047 (x0) - (rx) * 55 / 100, (y0) + (ry), \
00048 x0, (y0) + (ry)); \
00049 NPWGraphicsBezier(pdf, \
00050 (x0) + (rx) * 55 / 100, (y0) + (ry), \
00051 (x0) + (rx), (y0) + (ry) * 55 / 100, \
00052 (x0) + (rx), y0); \
00053 NPWGraphicsBezier(pdf, \
00054 (x0) + (rx), (y0) - (ry) * 55 / 100, \
00055 (x0) + (rx) * 55 / 100, (y0) - (ry), \
00056 x0, (y0) - (ry)); \
00057 NPWGraphicsBezier(pdf, \
00058 (x0) - (rx) * 55 / 100, (y0) - (ry), \
00059 (x0) - (rx), (y0) - (ry) * 55 / 100, \
00060 (x0) - (rx), y0); \
00061 NPWGraphicsClosePath(pdf); \
00062 } while (0)
00063
00065 #define NPWGraphicsStroke(pdf) \
00066 NPWGraphicsCmd(pdf, "S", "")
00068 #define NPWGraphicsCloseStroke(pdf) \
00069 NPWGraphicsCmd(pdf, "s", "")
00071 #define NPWGraphicsFill(pdf) \
00072 NPWGraphicsCmd(pdf, "f", "")
00074 #define NPWGraphicsFillEO(pdf) \
00075 NPWGraphicsCmd(pdf, "f*", "")
00077 #define NPWGraphicsFillStroke(pdf) \
00078 NPWGraphicsCmd(pdf, "B", "")
00080 #define NPWGraphicsFillEOStroke(pdf) \
00081 NPWGraphicsCmd(pdf, "B*", "")
00083 #define NPWGraphicsCloseFillStroke(pdf) \
00084 NPWGraphicsCmd(pdf, "b", "")
00086 #define NPWGraphicsCloseFillEOStroke(pdf) \
00087 NPWGraphicsCmd(pdf, "b*", "")
00089 #define NPWGraphicsEndPath(pdf) \
00090 NPWGraphicsCmd(pdf, "n", "")
00091
00093 #define NPWGraphicsClip(pdf) \
00094 NPWGraphicsCmd(pdf, "W", "")
00096 #define NPWGraphicsClipEO(pdf) \
00097 NPWGraphicsCmd(pdf, "W*", "")
00098
00100 #define NPWGraphicsGrayStroke(pdf, g) \
00101 NPWGraphicsCmd(pdf, "G", "f", (NPWFloat)(g))
00103 #define NPWGraphicsGray(pdf, g) \
00104 NPWGraphicsCmd(pdf, "g", "f", (NPWFloat)g)
00106 #define NPWGraphicsRGBStroke(pdf, r, g, b) \
00107 NPWGraphicsCmd(pdf, "RG", "fff", (NPWFloat)(r), (NPWFloat)(g), (NPWFloat)(b))
00109 #define NPWGraphicsRGB(pdf, r, g, b) \
00110 NPWGraphicsCmd(pdf, "rg", "fff", (NPWFloat)(r), (NPWFloat)(g), (NPWFloat)(b))
00112 #define NPWGraphicsCMYKStroke(pdf, c, m, y, k) \
00113 NPWGraphicsCmd(pdf, "K", "ffff", (NPWFloat)(c), (NPWFloat)(m), (NPWFloat)(y), (NPWFloat)(k))
00115 #define NPWGraphicsCMYK(pdf, c, m, y, k) \
00116 NPWGraphicsCmd(pdf, "k", "ffff", (NPWFloat)(c), (NPWFloat)(m), (NPWFloat)(y), (NPWFloat)(k))
00117
00119 enum
00120 {
00121 kNPWLineCapButt = 0,
00122 kNPWLineCapRound,
00123 kNPWLineCapSquare
00124 };
00125
00127 enum
00128 {
00129 kNPWLineJoinMitter = 0,
00130 kNPWLineJoinRound,
00131 kNPWLineJoinBevel
00132 };
00133
00135 #define NPWGraphicsSave(pdf) \
00136 NPWGraphicsCmd(pdf, "q", "")
00138 #define NPWGraphicsRestore(pdf) \
00139 NPWGraphicsCmd(pdf, "Q", "")
00141 #define NPWGraphicsConcatCTM(pdf, a, b, c, d, e, f) \
00142 NPWGraphicsCmd(pdf, "cm", "ffffff", \
00143 (NPWFloat)(a), (NPWFloat)(b), (NPWFloat)(c), (NPWFloat)(d), (NPWFloat)(e), (NPWFloat)(f))
00145 #define NPWGraphicsSetLineWidth(pdf, w) \
00146 NPWGraphicsCmd(pdf, "w", "f", (NPWFloat)(w))
00148 #define NPWGraphicsSetLineCap(pdf, c) \
00149 NPWGraphicsCmd(pdf, "j", "f", c)
00151 #define NPWGraphicsSetLineJoin(pdf, j) \
00152 NPWGraphicsCmd(pdf, "J", "f", j)
00154 #define NPWGraphicsSetMiterLimit(pdf, l) \
00155 NPWGraphicsCmd(pdf, "w", "f", (NPWFloat)(l))
00156
00159 #define NPWInlineImageBegin(pdf, w, h, cs, bpc, f) \
00160 do { \
00161 NPWWrite(pdf, "BI\n/W ", -1); \
00162 NPWWriteInt(pdf, w, -1); \
00163 NPWWrite(pdf, "\n/H ", -1); \
00164 NPWWriteInt(pdf, h, -1); \
00165 NPWWrite(pdf, "\n/CS ", -1); \
00166 NPWWrite(pdf, cs, -1); \
00167 NPWWrite(pdf, "\n/BPC ", -1); \
00168 NPWWriteInt(pdf, bpc, -1); \
00169 NPWWrite(pdf, "\n/F ", -1); \
00170 NPWWrite(pdf, f, -1); \
00171 NPWWrite(pdf, "\nID\n", -1); \
00172 } while (0)
00174 #define NPWInlineImageEnd(pdf) \
00175 NPWWrite(pdf, "EI\n", -1);
00176
00178 enum
00179 {
00180 kNPWTextRenderingModeFill = 0,
00181 kNPWTextRenderingModeStroke,
00182 kNPWTextRenderingModeFillStroke,
00183 kNPWTextRenderingModeInvisible,
00184 kNPWTextRenderingModeFillClip,
00185 kNPWTextRenderingModeStrokeClip,
00186 kNPWTextRenderingModeFillStrokeClip,
00187 kNPWTextRenderingModeClip
00188 };
00189
00191 #define NPWGraphicsSetCharSpace(pdf, s) \
00192 NPWGraphicsCmd(pdf, "Tc", "f", (NPWFloat)(s))
00194 #define NPWGraphicsSetWordSpace(pdf, s) \
00195 NPWGraphicsCmd(pdf, "Tw", "f", (NPWFloat)(s))
00197 #define NPWGraphicsSetHorizontalScaling(pdf, s) \
00198 NPWGraphicsCmd(pdf, "Tz", "f", (NPWFloat)(s))
00200 #define NPWGraphicsSetTextLeading(pdf, leading) \
00201 NPWGraphicsCmd(pdf, "TL", "f", (NPWFloat)(leading))
00203 #define NPWGraphicsSetTextFont(pdf, font, size) \
00204 NPWGraphicsCmd(pdf, "Tf", "Sf", font, -1, (NPWFloat)(size))
00206 #define NPWGraphicsSetTextRenderingMode(pdf, render) \
00207 NPWGraphicsCmd(pdf, "Tr", "f", (NPWFloat)(render))
00209 #define NPWGraphicsSetTextRise(pdf, rise) \
00210 NPWGraphicsCmd(pdf, "Ts", "f", (NPWFloat)(rise))
00211
00213 #define NPWGraphicsBeginText(pdf) \
00214 NPWGraphicsCmd(pdf, "BT", "")
00216 #define NPWGraphicsEndText(pdf) \
00217 NPWGraphicsCmd(pdf, "ET", "")
00219 #define NPWGraphicsMoveText(pdf, x, y) \
00220 NPWGraphicsCmd(pdf, "Td", "ff", (NPWFloat)(x), (NPWFloat)(y))
00222 #define NPWGraphicsNL(pdf) \
00223 NPWGraphicsCmd(pdf, "T*", "")
00225 #define NPWGraphicsShowText(pdf, str, len) \
00226 NPWGraphicsCmd(pdf, "Tj", "s", str, len)
00228 #define NPWGraphicsNLShowText(pdf, str, len) \
00229 NPWGraphicsCmd(pdf, "'", "s", str, len)
00231 #define NPWGraphicsNLShowTextSp(pdf, aw, ac, str, len) \
00232 NPWGraphicsCmd(pdf, "\"", "ffs", (NPWFloat)(aw), (NPWFloat)(ac), str, len)
00234 #define NPWGraphicsHorSkip(pdf, dx) \
00235 NPWGraphicsCmd(pdf, "TJ", "[f]", -(NPWFloat)dx)
00236
00237 #ifdef __cplusplus
00238 }
00239 #endif
00240
00241 #endif