summaryrefslogtreecommitdiff
path: root/lib/example/text.c
blob: d684c0eb1857b17552209a5e4775959ddc3df8e5 (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
/* text.c

   Example for including and using fonts 
   
   Part of the swftools package.

   Copyright (c) 2001 Rainer Böhme <rfxswf@reflex-studio.de>
 
   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 <stdio.h>
#include <fcntl.h>
#include <math.h>
#include "../rfxswf.h"

#include "demofont.c"  // five glyphs only:  f, l, o, s, w

/*
    Due to copyright reasons we don't include full typesets into
    the swftools package. But you can easily create fontdumps
    of your desired typo:

    * Create a swf file with all characters of your desired fonts
      (with any tool that can output swf files)

    * use the dumpfont example in this directory to dump font code

    * include dump code and adjust Font_<Fontname>() calls.

    Note: pdf2swf (Version 0.1.0) doesn't write ST_DEFINEFONTINFO tags,
    so you can't extract fonts out of documents made with pdf2swf. 
   
*/

#define BANNER_TEXT     "swftools" 
#define ID_FONT         2000
#define ID_BANNER       2001

int main(int argc, char ** argv)
{ SWF swf;
  TAG * t;
  SRECT r;
  RGBA rgb;
  U8 abits, gbits;
  int definefont2 = 1;

  int f;
  int width = 170;
  int height = 60;

  int points = 50; // <- change global text size here
  
  int textsize = points*20;   // adjust height
  int textscale = points*10;  // adjust spacing
  
  SWFFONT * font = Font_Demo_Font(ID_FONT); // change font name here

  /* adding layout to a font has the side effect that the 
     advance information is stored in the font itself, not
     in accompanying textfields- this is needed e.g. for
     edittext tags */
  if(definefont2)
      swf_FontAddLayout(font,0,0,0);

  swf_FontInitUsage(font);
  swf_FontUse(font,BANNER_TEXT);        // SWF reduces font information to the used glyphs
  swf_FontReduce(font);  
    
  memset(&swf,0x00,sizeof(SWF));

  swf.fileVersion    = 4;
  swf.frameRate      = 0x4000;
  swf.movieSize.xmax = 20*width;
  swf.movieSize.ymax = 20*height;

  swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
  t = swf.firstTag;

        rgb.r = 0xff;
        rgb.g = 0xff;
        rgb.b = 0xff;
        swf_SetRGB(t,&rgb);
  
  if(definefont2) {
      t = swf_InsertTag(t,ST_DEFINEFONT2);
	    swf_FontSetDefine2(t, font);
  } else {
      t = swf_InsertTag(t,ST_DEFINEFONT);
	    swf_FontSetDefine(t, font);
      t = swf_InsertTag(t,ST_DEFINEFONTINFO);
            swf_FontSetInfo(t, font);
  }

  t = swf_InsertTag(t,ST_DEFINETEXT);

        swf_SetU16(t,ID_BANNER);            // ID

        r.xmin = 0;
        r.ymin = 0;
        r.xmax = swf_TextGetWidth(font,BANNER_TEXT,textscale);
        r.ymax = textsize;
        
        swf_SetRect(t,&r);

        swf_SetMatrix(t,NULL);

        swf_TextCountBits(font,BANNER_TEXT,textscale,&gbits,&abits);
        
        swf_SetU8(t,gbits);
        swf_SetU8(t,abits);

        rgb.r = 0x00;
        rgb.g = 0x00;
        rgb.b = 0x00;

        swf_TextSetInfoRecord(t,font,textsize,&rgb,0,textsize);
        swf_TextSetCharRecord(t,font,BANNER_TEXT,textscale,gbits,abits);

        swf_SetU8(t,0);
        
      
    t = swf_InsertTag(t,ST_PLACEOBJECT2);

        swf_ObjectPlace(t,ID_BANNER,1,NULL,NULL,NULL);
 
    t = swf_InsertTag(t,ST_SHOWFRAME);
  
    t = swf_InsertTag(t,ST_END);
 
//  swf_WriteCGI(&swf);
 

  f = open("text.swf",O_RDWR|O_CREAT|O_TRUNC|O_BINARY,0644);
  if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
  close(f);

  swf_FreeTags(&swf);
//  swf_FontFree(font);

#ifdef __NT__
  system("start ..\\text.swf");
#endif
  
  return 0;
}