nx_x11_paint_text_5x7.nx source
↩ module page · 69 lines · 2382 B
1// nx_x11_paint_text_5x7.nx -- bits-up text rendering using the
2// canonical 5x7 bitmap font (nx_font_bitmap_5x7).
3//
4// For each character: get its 5x7 row pattern, paint a pixel rect
5// (size px_size) per ON bit. Composable with both windows and
6// pixmaps -- caller passes any X11 Drawable.
7//
8// Calling convention:
9// nx_x11_paint_text_5x7(c, drawable, gc, x, y, text, len, px_size)
10// - x, y : top-left pixel of text baseline
11// - px_size : pixel scale (1=tiny, 2=readable, 3=large)
12// - text/len : caller-allocated NUL-OK byte buffer
13// - gc : caller-created GC with foreground = text color
14//
15// Each char occupies px_size * (5+1) pixels horizontally and
16// px_size * (7+1) vertically (1 pixel of spacing baked in).
17//
18// license_tier: ORIGINAL
19// lineage_id: nishi_x11_paint_text_5x7_q10
20
21import "nx_syscalls.nx"
22import "nx_x11_connect.nx"
23import "nx_x11_window.nx"
24import "nx_x11_paint.nx"
25import "nx_font_bitmap_5x7.nx"
26
27// Draw one character at (x, y), each "pixel" of the 5x7 glyph
28// rendered as a px_size × px_size rect.
29func nx_x11_paint_glyph_5x7(c: *X11Conn, drawable: i64, gc: i64,
30 x: i64, y: i64,
31 ascii: i64, px_size: i64) -> i64 {
32 var row: i64 = 0
33 while row < 7 {
34 let bits: i64 = nx_font_5x7_glyph_row(ascii, row)
35 if bits >= 0 {
36 var col: i64 = 0
37 while col < 5 {
38 let mask: i64 = 1 << (4 - col)
39 if (bits & mask) != 0 {
40 let px: i64 = x + col * px_size
41 let py: i64 = y + row * px_size
42 nx_x11_fill_rect(c, drawable, gc, px, py, px_size, px_size)
43 }
44 col = col + 1
45 }
46 }
47 row = row + 1
48 }
49 return 0
50}
51
52// Draw a string of `len` chars starting at (x, y). Returns total
53// pixels of horizontal advance.
54func nx_x11_paint_text_5x7(c: *X11Conn, drawable: i64, gc: i64,
55 x: i64, y: i64,
56 text: *u8, len: i64, px_size: i64) -> i64 {
57 let glyph_w: i64 = (5 + 1) * px_size
58 var i: i64 = 0
59 while i < len {
60 let ch: i64 = (text[i] & 0xff) as i64
61 nx_x11_paint_glyph_5x7(c, drawable, gc, x + i * glyph_w, y, ch, px_size)
62 i = i + 1
63 }
64 return len * glyph_w
65}
66
67func main() -> i64 {
68 return 0
69}