#include <stdlib.h>
#include <stdio.h>
#include <math.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include <memory.h>
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
+#include <string.h>
#include "../gfxdevice.h"
#include "../gfxtools.h"
#include "../types.h"
#include "../bitio.h"
+#include "record.h"
typedef struct _internal {
gfxfontlist_t* fontlist;
#define OP_LINETO 0x0f
#define OP_SPLINETO 0x10
-int record_setparameter(struct _gfxdevice*dev, const char*key, const char*value)
+static int record_setparameter(struct _gfxdevice*dev, const char*key, const char*value)
{
internal_t*i = (internal_t*)dev->internal;
writer_writeU8(&i->w, OP_SETPARAM);
return 1;
}
-void dumpLine(writer_t*w, gfxline_t*line)
+static void dumpLine(writer_t*w, gfxline_t*line)
{
while(line) {
if(line->type == gfx_moveTo) {
}
writer_writeU8(w, OP_END);
}
-gfxline_t* readLine(reader_t*r)
+static gfxline_t* readLine(reader_t*r)
{
gfxline_t*start = 0, *pos = 0;
while(1) {
unsigned char op = reader_readU8(r);
if(op == OP_END)
break;
- gfxline_t*line = rfx_calloc(sizeof(gfxline_t));
+ gfxline_t*line = (gfxline_t*)rfx_calloc(sizeof(gfxline_t));
if(!start) {
start = pos = line;
} else {
}
return start;
}
-gfximage_t readImage(reader_t*r)
+static gfximage_t readImage(reader_t*r)
{
gfximage_t img;
img.width = reader_readU16(r);
img.height = reader_readU16(r);
- img.data = rfx_alloc(img.width*img.height*4);
+ img.data = (gfxcolor_t*)rfx_alloc(img.width*img.height*4);
r->read(r, img.data, img.width*img.height*4);
return img;
}
-gfxmatrix_t readMatrix(reader_t*r)
+static gfxmatrix_t readMatrix(reader_t*r)
{
gfxmatrix_t matrix;
matrix.m00 = reader_readDouble(r);
matrix.ty = reader_readDouble(r);
return matrix;
}
-gfxcolor_t readColor(reader_t*r)
+static gfxcolor_t readColor(reader_t*r)
{
gfxcolor_t col;
col.r = reader_readU8(r);
col.a = reader_readU8(r);
return col;
}
-gfxgradient_t* readGradient(reader_t*r)
+static gfxgradient_t* readGradient(reader_t*r)
{
gfxgradient_t*start = 0, *pos = 0;
while(1) {
U8 op = reader_readU8(r);
if(!op)
break;
- gfxgradient_t*g = rfx_calloc(sizeof(gfxgradient_t));
+ gfxgradient_t*g = (gfxgradient_t*)rfx_calloc(sizeof(gfxgradient_t));
if(!start) {
start = pos = g;
} else {
}
return start;
}
-gfxcxform_t* readCXForm(reader_t*r)
+static gfxcxform_t* readCXForm(reader_t*r)
{
U8 type = reader_readU8(r);
if(!type)
return 0;
- gfxcxform_t* c = rfx_calloc(sizeof(gfxcxform_t));
+ gfxcxform_t* c = (gfxcxform_t*)rfx_calloc(sizeof(gfxcxform_t));
c->rr = reader_readFloat(r); c->rg = reader_readFloat(r); c->rb = reader_readFloat(r); c->ra = reader_readFloat(r);
c->gr = reader_readFloat(r); c->gg = reader_readFloat(r); c->gb = reader_readFloat(r); c->ga = reader_readFloat(r);
c->br = reader_readFloat(r); c->bg = reader_readFloat(r); c->bb = reader_readFloat(r); c->ba = reader_readFloat(r);
return c;
}
-void dumpColor(writer_t*w, gfxcolor_t*color)
+static void dumpColor(writer_t*w, gfxcolor_t*color)
{
writer_writeU8(w, color->r);
writer_writeU8(w, color->g);
writer_writeU8(w, color->b);
writer_writeU8(w, color->a);
}
-void dumpMatrix(writer_t*w, gfxmatrix_t*matrix)
+static void dumpMatrix(writer_t*w, gfxmatrix_t*matrix)
{
writer_writeDouble(w, matrix->m00);
writer_writeDouble(w, matrix->m01);
writer_writeDouble(w, matrix->tx);
writer_writeDouble(w, matrix->ty);
}
-void dumpGradient(writer_t*w, gfxgradient_t*gradient)
+static void dumpGradient(writer_t*w, gfxgradient_t*gradient)
{
while(gradient) {
writer_writeU8(w, 1);
}
writer_writeU8(w, 0);
}
-void dumpImage(writer_t*w, gfximage_t*image)
+static void dumpImage(writer_t*w, gfximage_t*image)
{
writer_writeU16(w, image->width);
writer_writeU16(w, image->height);
w->write(w, image->data, image->width*image->height*4);
}
-void dumpCXForm(writer_t*w, gfxcxform_t*c)
+static void dumpCXForm(writer_t*w, gfxcxform_t*c)
{
if(!c) {
writer_writeU8(w, 0);
writer_writeFloat(w, c->ar); writer_writeFloat(w, c->ag); writer_writeFloat(w, c->ab); writer_writeFloat(w, c->aa);
}
}
-void dumpFont(writer_t*w, gfxfont_t*font)
+static void dumpFont(writer_t*w, gfxfont_t*font)
{
writer_writeString(w, font->id);
writer_writeU32(w, font->num_glyphs);
writer_writeU32(w, font->unicode2glyph[t]);
}
}
-gfxfont_t*readFont(reader_t*r)
+static gfxfont_t*readFont(reader_t*r)
{
- gfxfont_t* font = rfx_calloc(sizeof(gfxfont_t));
+ gfxfont_t* font = (gfxfont_t*)rfx_calloc(sizeof(gfxfont_t));
font->id = reader_readString(r);
font->num_glyphs = reader_readU32(r);
font->max_unicode = reader_readU32(r);
- font->glyphs = rfx_calloc(sizeof(gfxglyph_t)*font->num_glyphs);
- font->unicode2glyph = rfx_calloc(sizeof(font->unicode2glyph[0])*font->max_unicode);
+ font->glyphs = (gfxglyph_t*)rfx_calloc(sizeof(gfxglyph_t)*font->num_glyphs);
+ font->unicode2glyph = (int*)rfx_calloc(sizeof(font->unicode2glyph[0])*font->max_unicode);
int t;
for(t=0;t<font->num_glyphs;t++) {
font->glyphs[t].line = readLine(r);
font->glyphs[t].unicode = reader_readU32(r);
font->glyphs[t].name = reader_readString(r);
if(!font->glyphs[t].name[0]) {
- free(font->glyphs[t].name);
+ free((void*)(font->glyphs[t].name));
font->glyphs[t].name = 0;
}
}
return font;
}
-void record_stroke(struct _gfxdevice*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
+static void record_stroke(struct _gfxdevice*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
{
internal_t*i = (internal_t*)dev->internal;
writer_writeU8(&i->w, OP_STROKE);
dumpLine(&i->w, line);
}
-void record_startclip(struct _gfxdevice*dev, gfxline_t*line)
+static void record_startclip(struct _gfxdevice*dev, gfxline_t*line)
{
internal_t*i = (internal_t*)dev->internal;
writer_writeU8(&i->w, OP_STARTCLIP);
dumpLine(&i->w, line);
}
-void record_endclip(struct _gfxdevice*dev)
+static void record_endclip(struct _gfxdevice*dev)
{
internal_t*i = (internal_t*)dev->internal;
writer_writeU8(&i->w, OP_ENDCLIP);
}
-void record_fill(struct _gfxdevice*dev, gfxline_t*line, gfxcolor_t*color)
+static void record_fill(struct _gfxdevice*dev, gfxline_t*line, gfxcolor_t*color)
{
internal_t*i = (internal_t*)dev->internal;
writer_writeU8(&i->w, OP_FILL);
dumpLine(&i->w, line);
}
-void record_fillbitmap(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
+static void record_fillbitmap(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
{
internal_t*i = (internal_t*)dev->internal;
writer_writeU8(&i->w, OP_FILLBITMAP);
dumpCXForm(&i->w, cxform);
}
-void record_fillgradient(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
+static void record_fillgradient(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
{
internal_t*i = (internal_t*)dev->internal;
writer_writeU8(&i->w, OP_FILLGRADIENT);
dumpLine(&i->w, line);
}
-void record_addfont(struct _gfxdevice*dev, gfxfont_t*font)
+static void record_addfont(struct _gfxdevice*dev, gfxfont_t*font)
{
internal_t*i = (internal_t*)dev->internal;
writer_writeU8(&i->w, OP_ADDFONT);
i->fontlist = gfxfontlist_addfont(i->fontlist, font);
}
-void record_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
+static void record_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
{
internal_t*i = (internal_t*)dev->internal;
- if(!gfxfontlist_hasfont(i->fontlist, font))
+ if(font && !gfxfontlist_hasfont(i->fontlist, font))
record_addfont(dev, font);
writer_writeU8(&i->w, OP_DRAWCHAR);
- writer_writeString(&i->w, font->id);
+ if(font)
+ writer_writeString(&i->w, font->id);
+ else
+ writer_writeString(&i->w, "*NULL*");
writer_writeU32(&i->w, glyphnr);
dumpColor(&i->w, color);
dumpMatrix(&i->w, matrix);
}
-void record_startpage(struct _gfxdevice*dev, int width, int height)
+static void record_startpage(struct _gfxdevice*dev, int width, int height)
{
internal_t*i = (internal_t*)dev->internal;
writer_writeU8(&i->w, OP_STARTPAGE);
writer_writeU16(&i->w, height);
}
-void record_endpage(struct _gfxdevice*dev)
+static void record_endpage(struct _gfxdevice*dev)
{
internal_t*i = (internal_t*)dev->internal;
writer_writeU8(&i->w, OP_ENDPAGE);
}
-void record_drawlink(struct _gfxdevice*dev, gfxline_t*line, char*action)
+static void record_drawlink(struct _gfxdevice*dev, gfxline_t*line, const char*action)
{
internal_t*i = (internal_t*)dev->internal;
writer_writeU8(&i->w, OP_DRAWLINK);
double width = reader_readDouble(r);
double miterlimit = reader_readDouble(r);
gfxcolor_t color = readColor(r);
- gfx_capType captype = reader_readU8(r);
- gfx_joinType jointtype = reader_readU8(r);
+ gfx_capType captype;
+ int v = reader_readU8(r);
+ switch (v) {
+ case 0: captype = gfx_capButt; break;
+ case 1: captype = gfx_capRound; break;
+ case 2: captype = gfx_capSquare; break;
+ }
+ gfx_joinType jointtype;
+ v = reader_readU8(r);
+ switch (v) {
+ case 0: jointtype = gfx_joinMiter; break;
+ case 1: jointtype = gfx_joinRound; break;
+ case 2: jointtype = gfx_joinBevel; break;
+ }
gfxline_t* line = readLine(r);
device->stroke(device, line, width, &color, captype, jointtype,miterlimit);
gfxline_free(line);
break;
}
case OP_FILLGRADIENT: {
- gfxgradienttype_t type = reader_readU8(r);
+ gfxgradienttype_t type;
+ int v = reader_readU8(r);
+ switch (v) {
+ case 0:
+ type = gfxgradient_radial; break;
+ case 1:
+ type = gfxgradient_linear; break;
+ }
gfxgradient_t*gradient = readGradient(r);
gfxmatrix_t matrix = readMatrix(r);
gfxline_t* line = readLine(r);
}
case OP_DRAWCHAR: {
char* id = reader_readString(r);
- gfxfont_t*font = gfxfontlist_findfont(fontlist, id);
+ gfxfont_t*font = id?gfxfontlist_findfont(fontlist, id):0;
U32 glyph = reader_readU32(r);
gfxcolor_t color = readColor(r);
gfxmatrix_t matrix = readMatrix(r);
}
}
-void record_result_write(gfxresult_t*r, int filedesc)
+static void record_result_write(gfxresult_t*r, int filedesc)
{
internal_result_t*i = (internal_result_t*)r->internal;
write(filedesc, i->data, i->length);
}
-int record_result_save(gfxresult_t*r, char*filename)
+static int record_result_save(gfxresult_t*r, const char*filename)
{
internal_result_t*i = (internal_result_t*)r->internal;
FILE*fi = fopen(filename, "wb");
fclose(fi);
return 0;
}
-void*record_result_get(gfxresult_t*r, char*name)
+static void*record_result_get(gfxresult_t*r, const char*name)
{
internal_result_t*i = (internal_result_t*)r->internal;
if(!strcmp(name, "data")) {
}
return 0;
}
-void record_result_destroy(gfxresult_t*r)
+static void record_result_destroy(gfxresult_t*r)
{
internal_result_t*i = (internal_result_t*)r->internal;
free(i->data);i->data = 0;
}
-gfxresult_t* record_finish(struct _gfxdevice*dev)
+static gfxresult_t* record_finish(struct _gfxdevice*dev)
{
internal_t*i = (internal_t*)dev->internal;