#define OP_FINISH 0x0d
#define FLAG_SAME_AS_LAST 0x10
+#define FLAG_ZERO_FONT 0x20
#define LINE_MOVETO 0x0e
#define LINE_LINETO 0x0f
}
msg("<trace> record: %08x DRAWCHAR %d\n", glyphnr, dev);
- const char*font_id = font->id?font->id:"*NULL*";
+ const char*font_id = (font&&font->id)?font->id:"*NULL*";
gfxmatrix_t*l = &i->state.last_matrix[OP_DRAWCHAR];
+ U8 flags = 0;
+ if(!font)
+ flags |= FLAG_ZERO_FONT;
+
char same_font = i->state.last_string[OP_DRAWCHAR] && !strcmp(i->state.last_string[OP_DRAWCHAR], font_id);
char same_matrix = (l->m00 == matrix->m00) && (l->m01 == matrix->m01) && (l->m10 == matrix->m10) && (l->m11 == matrix->m11);
char same_color = !memcmp(color, &i->state.last_color[OP_DRAWCHAR], sizeof(gfxcolor_t));
- U8 flags = 0;
+
if(same_font && same_matrix && same_color)
flags |= FLAG_SAME_AS_LAST;
#endif
if(!(flags&FLAG_SAME_AS_LAST)) {
- writer_writeString(&i->w, font_id);
+ if(!(flags&FLAG_ZERO_FONT))
+ writer_writeString(&i->w, font_id);
dumpColor(&i->w, &i->state, color);
dumpMatrix(&i->w, &i->state, matrix);
i->state.last_string[OP_DRAWCHAR] = strdup(font_id);
case OP_DRAWCHAR: {
U32 glyph = reader_readU32(r);
gfxmatrix_t m = {1,0,0, 0,1,0};
- char* id = read_string(r, &state, op, flags);
+ char* id = 0;
+ if(!(flags&FLAG_ZERO_FONT))
+ id = read_string(r, &state, op, flags);
gfxcolor_t color = read_color(r, &state, op, flags);
gfxmatrix_t matrix = read_matrix(r, &state, op, flags);
}
msg("<trace> replay: DRAWCHAR font=%s glyph=%d", id, glyph);
out->drawchar(out, font, glyph, &color, &matrix);
- free(id);
+ if(id)
+ free(id);
break;
}
}
--- /dev/null
+/* vectors_to_fonts.c
+
+ Part of the swftools package.
+
+ Copyright (c) 2010 Matthias Kramm <kramm@quiss.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#include <stdlib.h>
+#include <memory.h>
+#include <math.h>
+#include "../gfxfilter.h"
+#include "../gfxtools.h"
+#include "../gfxpoly.h"
+#include "../gfxfont.h"
+#include "../types.h"
+#include "../mem.h"
+#include "../q.h"
+
+typedef struct _vglyph {
+ gfxglyph_t glyph;
+ struct _vglyph*next;
+} vglyph_t;
+
+typedef struct _internal {
+ vglyph_t*first_glyph;
+ vglyph_t*last_glyph;
+ gfxfont_t*font;
+ char first;
+ int glyph_nr;
+} internal_t;
+
+#define FONT_SIZE 1024.0
+
+static void pass1_fill(gfxfilter_t*f, gfxline_t*line, gfxcolor_t*color, gfxdevice_t*out)
+{
+ internal_t*i = (internal_t*)f->internal;
+ gfxbbox_t bbox = gfxline_getbbox(line);
+ double height = bbox.ymax - bbox.ymin;
+ double width = bbox.xmax - bbox.xmin;
+ double size = fmax(width,height);
+ if(fabs(size) < 1e-3) return;
+ double scale = FONT_SIZE/size;
+ gfxmatrix_t m = {scale, 0, -bbox.xmin*scale,
+ 0, scale, -bbox.ymax*scale};
+ line = gfxline_clone(line);
+ gfxline_transform(line, &m);
+ line = gfxline_restitch(line);
+ vglyph_t*v = rfx_calloc(sizeof(vglyph_t));
+ v->glyph.line = line;
+ v->glyph.advance = width*scale;
+ v->glyph.unicode = 32+i->glyph_nr;
+
+ i->last_glyph->next = v;
+ i->last_glyph = v;
+
+ gfxmatrix_t m2 = {1.0/scale, 0, bbox.xmin,
+ 0, 1.0/scale, bbox.ymax};
+ out->drawchar(out, 0, i->glyph_nr, color, &m2);
+
+ i->glyph_nr++;
+}
+static void pass1_stroke(gfxfilter_t*f, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit, gfxdevice_t*out)
+{
+ return;
+ internal_t*i = (internal_t*)f->internal;
+ gfxpoly_t*poly = gfxpoly_from_stroke(line, width, cap_style, joint_style, miterLimit, DEFAULT_GRID);
+ gfxline_t*line2 = gfxline_from_gfxpoly_with_direction(poly);
+ pass1_fill(f, line2, color, out);
+ gfxline_free(line2);
+ gfxpoly_destroy(poly);
+}
+
+static void make_font(internal_t*i)
+{
+ i->font = rfx_calloc(sizeof(gfxfont_t));
+ i->font->id = "SWFTools-Vector-Magic";
+ i->font->num_glyphs = i->glyph_nr;
+ i->font->glyphs = malloc(sizeof(gfxglyph_t)*i->font->num_glyphs);
+ i->font->ascent = FONT_SIZE;
+ i->font->descent = 0;
+ int pos = 0;
+ vglyph_t*g = i->first_glyph;
+ while(g) {
+ i->font->glyphs[pos] = g->glyph;
+ pos++;
+ g = g->next;
+ }
+ gfxfont_fix_unicode(i->font);
+}
+
+static void pass2_drawchar(gfxfilter_t*f, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix, gfxdevice_t*out)
+{
+ internal_t*i = (internal_t*)f->internal;
+ if(i->first) {
+ make_font(i);
+ out->addfont(out, i->font);
+ i->first = 0;
+ }
+ if(!font) {
+ font = i->font;
+
+ gfxcolor_t red = {255,254,1,1};
+ int x;
+ gfxmatrix_t m = {1.0, 0,0,
+ 0, 1.0,0};
+ out->drawchar(out, font, 1, &red, &m);
+
+ /*gfxmatrix_t m2 = {1.0, 0,600,
+ 0, 1.0,600};
+ out->drawchar(out, font, 1, &red, &m2);*/
+ gfxline_t*line = gfxline_makerectangle(0, 0, 1, 1);
+ gfximage_t img;
+ img.data = color;
+ img.width = 1;
+ img.height = 1;
+ out->fillbitmap(out, line, &img, &m, 0);
+ }
+ out->drawchar(out, font, glyphnr, color, matrix);
+}
+
+void gfxtwopassfilter_vectors_to_glyphs_init(gfxtwopassfilter_t*f)
+{
+ internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
+
+ memset(f, 0, sizeof(gfxtwopassfilter_t));
+ f->type = gfxfilter_twopass;
+
+ f->pass1.name = "vectors to glyphs pass 1";
+ f->pass1.fill = pass1_fill;
+ f->pass1.stroke = pass1_stroke;
+ f->pass1.internal = i;
+
+ f->pass2.name = "vectors to glyphs pass 2";
+ f->pass2.drawchar = pass2_drawchar;
+ f->pass2.internal = i;
+
+ i->first = 1;
+
+ i->first_glyph = rfx_calloc(sizeof(vglyph_t));
+ i->first_glyph->glyph.line = 0;
+ i->first_glyph->glyph.advance = FONT_SIZE;
+ i->first_glyph->glyph.unicode = 32;
+ i->last_glyph = rfx_calloc(sizeof(vglyph_t));
+ // dummy char
+ i->first_glyph->next = i->last_glyph;
+ i->last_glyph->glyph.line = 0;
+ i->last_glyph->glyph.advance = FONT_SIZE/8;
+ i->last_glyph->glyph.unicode = 33;
+ i->glyph_nr = 2;
+}
+
+