// File: /workspace/github_c_makefile_star2_O2/joncampbell123[P]swfhax/c4_swf2svg.c
// Function: do_dump_font_to_svg
void do_dump_font_to_svg(swf_reader *swf,FILE *fp) {
	unsigned int Xmin,Xmax,Ymin,Ymax;
	swf_SHAPE_reading r;
	unsigned int op=0;
	int pos_x,pos_y;

	Xmin = -20 * 50;
	Ymin = -20 * 50;
	Xmax =  20 * 50;
	Ymax =  20 * 50;

	fprintf(fp,"<?xml version=\"1.0\" standalone=\"no\"?>\n");
	fprintf(fp,"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
	fprintf(fp,"<svg width=\"%upx\" height=\"%upx\" viewBox=\"0 0 %u %u\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
		(Xmax - Xmin) / SWF_TWIPS_PER_PIXEL,
		(Ymax - Ymin) / SWF_TWIPS_PER_PIXEL,
		Xmax - Xmin,
		Ymax - Ymin);
	fprintf(fp,"  <style type=\"text/css\"><![CDATA[\n");
	if (outline_only)
		fprintf(fp,"   .blackpen { fill:none; stroke:black; stroke-width:20 }\n");
	else
		fprintf(fp,"   .blackpen { fill:black; stroke:none; }\n");

	fprintf(fp,"  ]]></style>\n");
#if 0
	fprintf(fp,"  <rect x=\"0\" y=\"0\" width=\"%u\" height=\"%u\" fill=\"none\" stroke=\"blue\" stroke-width=\"20\" /><!-- DEBUG BORDERLINE -->\n",
		Xmax - Xmin,
		Ymax - Ymin);
#endif

	pos_x = pos_y = 0;
	if (swf_reader_read_SHAPE_beginning(swf,&r) == 0) {
		while (swf_reader_read_SHAPE_record(swf,&r) == 0) {
			if (r.ShapeRecord_type == swf_shrec_EndShapeRecord)
				break;

			if (!op) {
				fprintf(fp,"  <path class=\"blackpen\" d=\"");
				op = 1;
			}

			if (r.ShapeRecord_type == swf_shrec_StraightEdgeRecord) {
				pos_x += r.shrec.edge.StraightEdgeRecord.DeltaX;
				pos_y += r.shrec.edge.StraightEdgeRecord.DeltaY;
				fprintf(fp,"L %d %d ",pos_x - Xmin,pos_y - Ymin);
			}
			else if (r.ShapeRecord_type == swf_shrec_CurvedEdgeRecord) {
				pos_x += r.shrec.edge.CurvedEdgeRecord.ControlDeltaX;
				pos_y += r.shrec.edge.CurvedEdgeRecord.ControlDeltaY;
				fprintf(fp,"Q %d %d ",pos_x - Xmin,pos_y - Ymin);
				pos_x += r.shrec.edge.CurvedEdgeRecord.AnchorDeltaX;
				pos_y += r.shrec.edge.CurvedEdgeRecord.AnchorDeltaY;
				fprintf(fp,"%d %d ",pos_x - Xmin,pos_y - Ymin);
			}
			else if (r.ShapeRecord_type == swf_shrec_StyleChangeRecord) {
				if (r.shrec.style.StyleChangeRecord.StateNewStyles) {
#if 0
					fprintf(stderr,"NewStyles in Font??\n");
#endif
					break;
				}

				if (r.shrec.style.StyleChangeRecord.StateMoveTo) {
					pos_x = r.shrec.style.StyleChangeRecord.MoveDeltaX;
					pos_y = r.shrec.style.StyleChangeRecord.MoveDeltaY;
				}

				fprintf(fp,"M %d %d ",pos_x - Xmin,pos_y - Ymin);
			}
		}

		if (op) {
			fprintf(fp,"\" />\n");
			op = 0;
		}
	}

	fprintf(fp,"</svg>\n");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x4d46(%rip), %rdi      # 0x6020
pushq $0x26
popq %rsi
pushq $0x1
popq %r15
movq %r15, %rdx
movq %rbx, %rcx
callq 0x11b0
leaq 0x4d54(%rip), %rdi      # 0x6047
pushq $0x63
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x11b0
leaq 0x4da3(%rip), %rsi      # 0x60ab
pushq $0x64
popq %rcx
movq %rbx, %rdi
movl %ecx, %edx
movl $0x7d0, %r8d            # imm = 0x7D0
movl $0x7d0, %r9d            # imm = 0x7D0
xorl %eax, %eax
callq 0x10e0
leaq 0x4de8(%rip), %rdi      # 0x6112
pushq $0x23
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x11b0
cmpb $0x1, 0x8e39(%rip)      # 0xa178
jne 0x134c
leaq 0x4dee(%rip), %rdi      # 0x6136
pushq $0x3a
jmp 0x1355
leaq 0x4e1e(%rip), %rdi      # 0x6171
pushq $0x2a
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11b0
leaq 0x4e34(%rip), %rdi      # 0x619c
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11b0
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x3ded
testl %eax, %eax
jne 0x149d
movb $0x1, %r13b
leaq -0x58(%rbp), %r15
movq $0x0, -0x30(%rbp)
xorl %r12d, %r12d
movq %r14, %rdi
movq %r15, %rsi
callq 0x3e44
testl %eax, %eax
jne 0x1482
movb -0x48(%rbp), %al
testb %al, %al
je 0x1482
testb $0x1, %r13b
je 0x13d8
leaq 0x4de4(%rip), %rdi      # 0x61ab
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11b0
movb -0x48(%rbp), %al
cmpb $0x1, %al
je 0x1400
movzbl %al, %eax
cmpl $0x3, %eax
je 0x1425
xorl %r13d, %r13d
cmpl $0x2, %eax
jne 0x139c
movq -0x30(%rbp), %rcx
addl -0x40(%rbp), %ecx
addl -0x3c(%rbp), %r12d
leaq 0x4dca(%rip), %rsi      # 0x61c8
jmp 0x141e
movzwl -0x44(%rbp), %eax
testb $0x1, %al
movq -0x30(%rbp), %rcx
jne 0x1488
testb $0x10, %al
je 0x1417
movl -0x40(%rbp), %ecx
movl -0x3c(%rbp), %r12d
leaq 0x4dbc(%rip), %rsi      # 0x61da
movl $0x3e8, %eax            # imm = 0x3E8
jmp 0x1465
movq -0x30(%rbp), %r13
addl -0x40(%rbp), %r13d
addl -0x3c(%rbp), %r12d
movl $0x3e8, %eax            # imm = 0x3E8
leal (%rax,%r13), %edx
leal (%r12,%rax), %ecx
movq %rbx, %rdi
leaq 0x4d89(%rip), %rsi      # 0x61d1
xorl %eax, %eax
callq 0x10e0
movq %r13, %rcx
movl $0x3e8, %eax            # imm = 0x3E8
addl -0x38(%rbp), %ecx
addl -0x34(%rbp), %r12d
leaq 0x4d65(%rip), %rsi      # 0x61ca
movq %rcx, -0x30(%rbp)
leal (%rcx,%rax), %edx
leal (%r12,%rax), %ecx
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10e0
jmp 0x139c
testb $0x1, %r13b
jne 0x149d
leaq 0x520e(%rip), %rdi      # 0x669d
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11b0
leaq 0x4d3f(%rip), %rdi      # 0x61e3
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11b0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq