Jspice3
labeltxt.c File Reference
#include "spice.h"
#include "sced.h"
#include "plotdev.h"
#include <ctype.h>
Include dependency graph for labeltxt.c:

Go to the source code of this file.

Macros

#define FontW   8
 
#define FontH   16
 
#define CharTab   label_font
 

Functions

static int setcode ()
 
static void xform_cell ()
 
void SetScaledTextClip (int xl, int yl, int xu, int yu)
 
void ScaledTextBB (char *string, int *wid, int *hei)
 
int ScaledText (char *text, int x, int y, int degrees, int scale)
 
static int setcode (int deg)
 
static void xform_cell (unsigned short *out, unsigned short *in, int w, int h, int code, int shift)
 

Variables

static int Xl
 
static int Yl
 
static int Xu = 0x7fff
 
static int Yu = 0x7fff
 
static unsigned short label_font []
 

Macro Definition Documentation

#define CharTab   label_font

Definition at line 157 of file labeltxt.c.

#define FontH   16

Definition at line 29 of file labeltxt.c.

#define FontW   8

Definition at line 28 of file labeltxt.c.

Function Documentation

int ScaledText ( char *  text,
int  x,
int  y,
int  degrees,
int  scale 
)

Definition at line 160 of file labeltxt.c.

164 {
165  int i, ii, j, k, tx;
166  int xnow, ynow;
167  int fheight, fwidth;
168  unsigned short rotbuf[16], *ctab, mask;
169  unsigned short cbuf;
170  char *str0, *str1;
171 
172  if (scale < 1 || scale > 10) return (0);
173  if (text == NULL) return (0);
174 
175  if (!strcmp(dispdev->name,"wp")) {
176  /* use plain text for now */
177  DevText(text,x,y);
178  return (0);
179  }
180 
181  /* Hack! If degrees is >= 90, an angle is assumed.
182  * Otherwise, it is assumed to be an encoded transform.
183  */
184  if (degrees >= 90) degrees /= 90;
185 
186  if (!strcmp(dispdev->name,"postscript")) {
187  PS_ScaledText(text,x,y,degrees);
188  return (0);
189  }
190 
191  if (degrees & 1) {
192  fheight = FontW;
193  fwidth = FontH;
194  if (degrees & 2) {
195  if (!(degrees & 4))
196  y -= strlen(text)*fheight*scale;
197  if (degrees & 8)
198  x -= fwidth*scale;
199  }
200  else {
201  if (!(degrees & 8))
202  x -= fwidth*scale;
203  if (degrees & 4)
204  y -= strlen(text)*fheight*scale;
205  }
206  }
207  else {
208  fheight = FontH;
209  fwidth = FontW;
210  if (degrees & 2) {
211  if (!(degrees & 8))
212  x -= strlen(text)*fwidth*scale;
213  if (!(degrees & 4))
214  y -= fheight*scale;
215  }
216  else {
217  if (degrees & 8)
218  x -= strlen(text)*fwidth*scale;
219  if (degrees & 4)
220  y -= fheight*scale;
221  }
222  }
223  degrees = setcode(degrees);
224 
225  str0 = text;
226  str1 = text + strlen(text);
227  while (str0 != str1) {
228 
229  if (degrees & 8) {
230  if ((tx = (*--str1 & 0x7f) - ' ') < 0) tx = 0;
231  }
232  else
233  if ((tx = (*str0++ & 0x7f) - ' ') < 0) tx = 0;
234 
235  ctab = CharTab + tx*FontH;
236  xform_cell(rotbuf,ctab,fwidth,fheight,degrees,fwidth);
237  ctab = rotbuf + fheight - 1;
238 
239  ynow = y;
240  for (i = fheight; i; i--, ctab--) {
241  for (j = scale; j; j--) {
242  if (ynow >= Yl && ynow <= Yu) {
243  xnow = x;
244  for (mask = 0x8000,ii = fwidth; ii; mask >>= 1,ii--) {
245  for (k = scale; k; k--) {
246  if (xnow >= Xl && xnow <= Xu) {
247  if (*ctab & mask)
248  DevPixel(xnow,ynow);
249  }
250  xnow++;
251  }
252  }
253  }
254  else
255  x += fwidth*scale;
256  ynow++;
257  }
258  }
259  if (degrees & 4) {
260  y += fheight*scale;
261  continue;
262  }
263  x += fwidth*scale;
264  }
265  return (0);
266 }
static int Yu
Definition: labeltxt.c:17
static complex ii
Definition: vectors.c:19
void DevText()
char * name
Definition: plotdev.h:60
DISPDEVICE * dispdev
Definition: display.c:112
#define FontW
Definition: labeltxt.c:28
#define CharTab
Definition: labeltxt.c:157
#define NULL
Definition: spdefs.h:121
static int Yl
Definition: labeltxt.c:17
void DevPixel()
static void xform_cell()
static int Xu
Definition: labeltxt.c:17
#define FontH
Definition: labeltxt.c:29
static int Xl
Definition: labeltxt.c:17
int PS_ScaledText()
static int setcode()
void ScaledTextBB ( char *  string,
int *  wid,
int*  hei 
)

Definition at line 144 of file labeltxt.c.

148 {
149  *wid = 0;
150  *hei = 0;
151  if (string == NULL) return;
152  *wid = strlen(string) * FontW;
153  *hei = FontH;
154 }
#define FontW
Definition: labeltxt.c:28
#define NULL
Definition: spdefs.h:121
#define FontH
Definition: labeltxt.c:29
static int setcode ( )
static
static int setcode ( int  deg)
static

Definition at line 270 of file labeltxt.c.

273 {
274  /*
275  * returned bit field:
276  * 0x8: load text backward
277  * 0x4: rotation
278  * 0x2: reverse y data
279  * 0x1: reverse x data
280  *
281  * Assumes input bit field:
282  * 0x8: mirror x
283  * 0x4: mirror y
284  * 0x3: 0-no rotation, 1-90, 2-180, 3-270
285  */
286 
287  int mx = 0,my = 0;
288  int rotn;
289  int xf = 0;
290 
291  rotn = deg & 3;
292  if (deg & 8) mx = 1;
293  if (deg & 4) my = 1;
294 
295  if ((mx && rotn == 0) || (!mx && rotn == 2) ||
296  (my && rotn == 1) || (!my && rotn == 3))
297  xf |= 8;
298  if (rotn & 1)
299  xf |= 4;
300  if ((my && (rotn == 0 || rotn == 1)) ||
301  (!my && (rotn == 2 || rotn == 3)))
302  xf |= 2;
303  if ((mx && (rotn == 0 || rotn == 3)) ||
304  (!mx && (rotn == 1 || rotn == 2)))
305  xf |= 1;
306  return (xf);
307 }
void SetScaledTextClip ( int  xl,
int  yl,
int  xu,
int  yu 
)

Definition at line 131 of file labeltxt.c.

135 {
136  Xl = xl;
137  Yl = yl;
138  Xu = xu;
139  Yu = yu;
140 }
static int Yu
Definition: labeltxt.c:17
static int Yl
Definition: labeltxt.c:17
static int Xu
Definition: labeltxt.c:17
static int Xl
Definition: labeltxt.c:17
static void xform_cell ( )
static
static void xform_cell ( unsigned short *  out,
unsigned short*  in,
int  w,
int  h,
int  code,
int  shift 
)
static

Definition at line 311 of file labeltxt.c.

315 {
316  int i, j, k, l;
317 
318  for (i = 0; i < h; i++) {
319  k = ((code & 2) ? h-i-1 : i);
320  if (code & 4) {
321  for (j = 0,out[i] = 0; j < w; j++) {
322  l = ((code & 1) ? (w-j-1) : j);
323  out[i] |= ((in[j] >> k) & 1) << l;
324  }
325  }
326  else {
327  if (code & 1)
328  for (j = 0,out[i] = 0; j < w; j++)
329  out[i] |= ((in[k] >> j) & 1) << (w-j-1);
330  else
331  out[i] = in[k];
332  }
333  }
334  if (shift)
335  for (i = 0,j = 16-shift; i < h; i++)
336  out[i] <<= j;
337 }
Definition: cddefs.h:169
Definition: cddefs.h:312

Variable Documentation

unsigned short label_font[]
static

Definition at line 30 of file labeltxt.c.

int Xl
static

Definition at line 17 of file labeltxt.c.

int Xu = 0x7fff
static

Definition at line 17 of file labeltxt.c.

int Yl
static

Definition at line 17 of file labeltxt.c.

int Yu = 0x7fff
static

Definition at line 17 of file labeltxt.c.