aboutsummaryrefslogtreecommitdiff
path: root/pkg/images/tv/tvmark/mktext.x
blob: 06a99b378856165661e6b156405861bd7a764b78 (plain) (blame)
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
160
161
162
163
164
include <mach.h>
include <imhdr.h>

define	FONTWIDE	6
define	FONTHIGH	7
define	SZ_LOOKUP	128
define	SZ_FONT		455
define	SZ_PIXARY	5

# MK_TEXTIM -- Write a text string into an image using a pixel font for speed.
# Characters are made twice as big as the font by doubling in both axes.

procedure mk_textim (im, s, x, y, xmag, ymag, value, center)

pointer	im				# image to put the text in.
char	s[ARB]				# text to put in the image.
int	x, y				# x, y position in the image.
int	xmag, ymag			# x, y magnification values.
int	value				# value to use in image for text.
int	center				# center the string

int	numrow, numcol, numchars, fonthigh, fontwide, xinit, yinit
int	i, l, ch, nchar, line, ip, pixary[SZ_PIXARY]
pointer	lineget, lineput

int	strlen()
pointer	imgl2s(), impl2s()
errchk	imgl2s, impl2s

begin
	# Find the length of the string.
	numchars = strlen (s)
	if (numchars <= 0)
	    return

	# Calculate height and width of magnified font.
	fonthigh = FONTHIGH * ymag
	fontwide = FONTWIDE * xmag

	# Check for row/col out of bounds.
	numcol= IM_LEN(im,1)
	numrow = IM_LEN(im,2)

	# Compute the initial position of the string truncating characters
	# is necessary.
	if (center == YES)
	    xinit = x - fontwide * numchars / 2
	else
	    xinit = x
	for (ip = 1; ip <= numchars; ip = ip + 1) {
	    if (xinit >= 1)
		break
	    xinit = xinit + fontwide 
	}

	# Return if beginning of string is off image.
	if (xinit < 1 || xinit > numcol)
	    return

	# Truncate the string.
	if (xinit > numcol - fontwide * (numchars - ip + 1)) {
	    numchars = int ((numcol - xinit) / fontwide)
	    if (numchars <= 0)
	        return
	}

	# Return if the text does not fit in the image.
	if (center == YES)
	    yinit = y - fonthigh * numchars / 2
	else
	    yinit = y
	if ((yinit <= 0) || (yinit > numrow - fonthigh))
	    return

	# For each line of the text (backward).
	for (i = 1; i <= 7; i = i + 1) {

	    line = yinit + (i-1) * ymag

	    do l = 1, ymag {

	        # Get and put the line of the image.
	        lineput = impl2s (im, line+(l-1))
	        lineget = imgl2s (im, line+(l-1))
	        call amovs (Mems[lineget], Mems[lineput], numcol)

	        # Put out the font.
	        do ch = ip, numchars {
	            nchar = int (s[ch])
		    call mk_pixbit (nchar, 8 - i, pixary)
		    call mk_putpix (pixary, Mems[lineput], numcol,
			xinit+(ch-1)*fontwide, value, xmag)
	        }

	    }
	}
end


# MK_PIXBIT -- Look up which bits should be set for this character on this line.

procedure mk_pixbit (code, line, bitarray)

int	code		# character we are writing
int	line		# line of the character we are writing
int	bitarray[ARB]	# bit-array to receive data

int	pix, i
short	asciilook[SZ_LOOKUP], font[SZ_FONT]
int	bitupk()

include	"pixelfont.inc"
include	"asciilook.inc"

begin
	pix = font[asciilook[code+1]+line-1]
	bitarray[5] = bitupk (pix, 1, 1)
	bitarray[4] = bitupk (pix, 4, 1)
	bitarray[3] = bitupk (pix, 7, 1)
	bitarray[2] = bitupk (pix, 10, 1)
	bitarray[1] = bitupk (pix, 13, 1)
end


# MK_PUTPIX -- Put one line of one character into the data array.

procedure mk_putpix (pixary, array, size, position, value, xmag)

int	pixary[ARB]		# array of pixels in character
int	size, position		# size of data array
short	array[size]		# data array in which to put character line
int	value			# value to use for character pixels
int	xmag			# x-magnification of text

int	i, k, x

begin
	do i = 1, 5 {
	    if (pixary[i] == 1) {
		x = position + (i-1) * xmag
		do k = 1, xmag
		    array[x+(k-1)] = value
	    }
	}
end


# MK_TLIMITS -- Compute the column and line limits of a text string.

procedure mk_tlimits (str, x, y, xmag, ymag, ncols, nlines, x1, x2, y1, y2)

char	str[ARB]		# string to be written to the image
int	x, y			# starting position of the string
int	xmag, ymag		# magnification factor
int	ncols, nlines		# dimensions of the image
int	x1, x2			# column limits
int	y1, y2			# line limits

begin
	x1 = max (1, min (y, ncols))
	x2 = min (ncols, max (1, y + 5 * xmag))
	y1 = max (1, min (y, nlines))
	y2 = min (nlines, max (1, y + 6 * ymag))
end