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 165 166 167 168 169 170 171 172 173
|
/* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */
#include "ui_decsp_font.h"
#include <stdio.h>
#include <pobl/bl_mem.h> /* malloc */
#include <pobl/bl_str.h> /* strdup */
#include <pobl/bl_util.h>
/* --- static functions --- */
static void draw_check(u_char *fb, u_int width_bytes, u_int height) {
int y;
u_char check1 = 0xaa;
u_char check2 = 0x55;
for (y = 0; y < height; y++) {
if ((y & 1) == 0) {
memset(fb, check1, width_bytes);
} else {
memset(fb, check2, width_bytes);
}
fb += width_bytes;
}
}
static void draw_vline(u_char *fb, u_int width_bytes, int x, int beg_y, int end_y) {
int y;
int mask;
fb += (width_bytes * beg_y);
fb += (x / 8);
mask = (1 << (8 - (x&7) - 1));
for (y = beg_y; y <= end_y; y++) {
*fb |= mask;
fb += width_bytes;
}
}
static void draw_hline(u_char *fb, u_int width_bytes, int beg_x, int end_x, int y) {
int x;
fb += (width_bytes * y);
for (x = beg_x; x <= end_x; x++) {
fb[x/8] |= (1 << (8 - (x&7) - 1));
}
}
static void draw_diamond(u_char *fb, u_int width_bytes, u_int width, u_int height) {
int x;
int y;
u_int mod = height / 2;
for (y = 0; y < mod; y++) {
x = (width * (mod - y - 1) / mod + 1) / 2;
draw_hline(fb, width_bytes, x, width - x - 1, y);
}
for (; y < height; y++) {
x = (width * (y - mod) / mod + 1) / 2;
draw_hline(fb, width_bytes, x, width - x - 1, y);
}
}
/* --- global functions --- */
int ui_load_decsp_xfont(XFontStruct *xfont, const char *decsp_id) {
u_int width;
u_int height;
int count;
u_int glyph_size;
u_char *p;
if (sscanf(decsp_id, "decsp-%dx%d", &width, &height) != 2) {
return 0;
}
xfont->file = strdup(decsp_id);
xfont->glyph_width_bytes = (width + 7) / 8;
xfont->width = xfont->width_full = width;
xfont->height = height;
xfont->ascent = height - height / 6;
xfont->min_char_or_byte2 = 0x1;
xfont->max_char_or_byte2 = 0x1e;
xfont->num_glyphs = 30;
glyph_size = xfont->glyph_width_bytes * height;
xfont->glyphs = calloc(30, glyph_size);
xfont->glyph_offsets = calloc(30, sizeof(xfont->glyph_offsets[0]));
xfont->glyph_indeces = calloc(30, sizeof(int16_t));
xfont->ref_count = 1;
for (count = 0; count < 30; count++) {
xfont->glyph_offsets[count] = count * glyph_size;
((int16_t*)xfont->glyph_indeces)[count] = count;
}
/*
* Glyph map
*
* Used , Used , None , None , None , None , None ,
* None , None , None , Used , Used , Used , Used , Used ,
* Used , Used , Used , Used , Used , Used , Used , Used ,
* Used , Used , None , None , None , None , Used
*/
p = xfont->glyphs;
draw_diamond(p, xfont->glyph_width_bytes, width, height);
p += glyph_size;
draw_check(p, xfont->glyph_width_bytes, height);
p += (glyph_size * (0x0a - 0x01));
draw_hline(p, xfont->glyph_width_bytes, 0, width / 2 - 1, height / 2 - 1);
draw_vline(p, xfont->glyph_width_bytes, width / 2 - 1, 0, height / 2 - 1);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, 0, width / 2 - 1, height / 2 - 1);
draw_vline(p, xfont->glyph_width_bytes, width / 2 - 1, height / 2 - 1, height - 1);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, width / 2 - 1, width - 1, height / 2 - 1);
draw_vline(p, xfont->glyph_width_bytes, width / 2 - 1, height / 2 - 1, height - 1);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, width / 2 - 1, width - 1, height / 2 - 1);
draw_vline(p, xfont->glyph_width_bytes, width / 2 - 1, 0, height / 2 - 1);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, 0, width - 1, height / 2 - 1);
draw_vline(p, xfont->glyph_width_bytes, width / 2 - 1, 0, height - 1);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, 0, width - 1, 0);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, 0, width - 1, height / 4 - 1);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, 0, width - 1, height / 2 - 1);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, 0, width - 1, height * 3 / 4 - 1);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, 0, width - 1, height - 1);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, width / 2 - 1, width - 1, height / 2 - 1);
draw_vline(p, xfont->glyph_width_bytes, width / 2 - 1, 0, height - 1);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, 0, width / 2 - 1, height / 2 - 1);
draw_vline(p, xfont->glyph_width_bytes, width / 2 - 1, 0, height - 1);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, 0, width - 1, height / 2 - 1);
draw_vline(p, xfont->glyph_width_bytes, width / 2 - 1, 0, height / 2 - 1);
p += glyph_size;
draw_hline(p, xfont->glyph_width_bytes, 0, width - 1, height / 2 - 1);
draw_vline(p, xfont->glyph_width_bytes, width / 2 - 1, height / 2 - 1, height - 1);
p += glyph_size;
draw_vline(p, xfont->glyph_width_bytes, width / 2 - 1, 0, height - 1);
p += (glyph_size * (0x1d - 0x18));
draw_hline(p, xfont->glyph_width_bytes, width / 2 - 2, width / 2, height / 2 - 1);
draw_vline(p, xfont->glyph_width_bytes, width / 2 - 1, height / 2 - 2, height / 2);
return 1;
}
/* unload_pcf() in ui_font.c completely frees memory. */
|